Add language in import and export form, with handle by FormatterData

modifié:         core/lib/Thelia/Controller/Admin/ExportController.php
	modifié:         core/lib/Thelia/Controller/Admin/ImportController.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php
	modifié:         core/lib/Thelia/Form/ExportForm.php
	modifié:         core/lib/Thelia/Form/ImportForm.php
	modifié:         templates/backOffice/default/ajax/export-modal.html
	modifié:         templates/backOffice/default/ajax/import-modal.html
	modifié:         templates/backOffice/default/export-page.html
	modifié:         templates/backOffice/default/import-page.html
This commit is contained in:
Benjamin Perche
2014-07-21 16:17:37 +02:00
parent f83251d31d
commit 6c8411f0c0
9 changed files with 197 additions and 27 deletions

View File

@@ -30,6 +30,8 @@ use Thelia\ImportExport\Export\ExportHandler;
use Thelia\ImportExport\Export\ImagesExportInterface;
use Thelia\Model\ExportCategoryQuery;
use Thelia\Model\ExportQuery;
use Thelia\Model\Lang;
use Thelia\Model\LangQuery;
/**
* Class ExportController
@@ -88,6 +90,10 @@ class ExportController extends BaseAdminController
try {
$boundForm = $this->validateForm($form);
$lang = LangQuery::create()->findPk(
$boundForm->get("language")->getData()
);
$archiveBuilder = null;
/**
@@ -115,7 +121,8 @@ class ExportController extends BaseAdminController
$export->getHandleClassInstance($this->container),
$archiveBuilder,
$boundForm->get("images")->getData(),
$boundForm->get("documents")->getData()
$boundForm->get("documents")->getData(),
$lang
);
} catch (FormValidationException $e) {
@@ -153,6 +160,7 @@ class ExportController extends BaseAdminController
AbstractFormatter $formatter,
ExportHandler $handler,
AbstractArchiveBuilder $archiveBuilder = null,
Lang $lang,
$includeImages = false,
$includeDocuments = false
) {
@@ -160,7 +168,7 @@ class ExportController extends BaseAdminController
* Build an event containing the formatter and the handler.
* Used for specific configuration (e.g: XML node names)
*/
$data = $handler->buildFormatterData();
$data = $handler->buildFormatterData()->setLang($lang);
$event = new ImportExportEvent($formatter, $handler , $data);
$filename = $formatter::FILENAME . "." . $formatter->getExtension();
@@ -288,6 +296,7 @@ class ExportController extends BaseAdminController
$this->getParserContext()
->set("HAS_IMAGES", $export->hasImages($this->container))
->set("HAS_DOCUMENTS", $export->hasDocuments($this->container))
->set("CURRENT_LANG_ID", $this->getSession()->getLang()->getId())
;
/** Then render the form */

View File

@@ -30,6 +30,8 @@ use Thelia\Form\ImportForm;
use Thelia\ImportExport\Import\ImportHandler;
use Thelia\Model\ImportCategoryQuery;
use Thelia\Model\ImportQuery;
use Thelia\Model\Lang;
use Thelia\Model\LangQuery;
/**
* Class ImportController
@@ -79,6 +81,10 @@ class ImportController extends BaseAdminController
try {
$boundForm = $this->validateForm($form);
$lang = LangQuery::create()->findPk(
$boundForm->get("language")->getData()
);
/** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
$file = $boundForm->get("file_upload")->getData();
@@ -139,7 +145,8 @@ class ImportController extends BaseAdminController
$content,
$handler,
$formatter,
$archiveBuilder
$archiveBuilder,
$lang
);
} catch (FormValidationException $e) {
@@ -282,14 +289,18 @@ class ImportController extends BaseAdminController
$content,
ImportHandler $handler,
AbstractFormatter $formatter = null,
AbstractArchiveBuilder $archiveBuilder = null
AbstractArchiveBuilder $archiveBuilder = null,
Lang $lang = null
) {
$event = new ImportExportEvent($formatter, $handler, null, $archiveBuilder);
$event->setContent($content);
$this->dispatch(TheliaEvents::IMPORT_AFTER_DECODE, $event);
$data = $formatter->decode($event->getContent());
$data = $formatter
->decode($event->getContent())
->setLang($lang)
;
$event->setContent(null)->setData($data);
$this->dispatch(TheliaEvents::IMPORT_AFTER_DECODE, $event);
@@ -385,6 +396,7 @@ class ImportController extends BaseAdminController
$parserContext
->set("ALLOWED_MIME_TYPES", implode(",", $mimeTypes))
->set("ALLOWED_EXTENSIONS", implode(", ", $formats))
->set("CURRENT_LANG_ID", $this->getSession()->getLang()->getId())
;
/** Then render the form */