diff --git a/core/lib/Thelia/Controller/Admin/ExportController.php b/core/lib/Thelia/Controller/Admin/ExportController.php index 7c04b7a7e..efa7db238 100644 --- a/core/lib/Thelia/Controller/Admin/ExportController.php +++ b/core/lib/Thelia/Controller/Admin/ExportController.php @@ -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 */ diff --git a/core/lib/Thelia/Controller/Admin/ImportController.php b/core/lib/Thelia/Controller/Admin/ImportController.php index 2846d6854..96ec4ed85 100644 --- a/core/lib/Thelia/Controller/Admin/ImportController.php +++ b/core/lib/Thelia/Controller/Admin/ImportController.php @@ -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 */ diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php index 48da31789..6b81aa664 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php @@ -14,6 +14,8 @@ namespace Thelia\Core\FileFormat\Formatting; use Propel\Runtime\ActiveQuery\ModelCriteria; use Propel\Runtime\Map\TableMap; use Thelia\Core\Translation\Translator; +use Thelia\Model\Lang; + /** * Class FormatterData * @package Thelia\Core\FileFormat\Formatting @@ -21,6 +23,8 @@ use Thelia\Core\Translation\Translator; */ class FormatterData { + protected $lang; + /** @var array */ protected $data = array(); @@ -227,4 +231,16 @@ class FormatterData { return $this->reverseAliases($this->data, $this->aliases); } + + public function setLang(Lang $lang) + { + $this->lang = $lang; + + return $this; + } + + public function getLang() + { + return $this->lang; + } } diff --git a/core/lib/Thelia/Form/ExportForm.php b/core/lib/Thelia/Form/ExportForm.php index 9449127ba..b149bcdc9 100644 --- a/core/lib/Thelia/Form/ExportForm.php +++ b/core/lib/Thelia/Form/ExportForm.php @@ -11,8 +11,11 @@ /*************************************************************************************/ namespace Thelia\Form; +use Symfony\Component\Validator\Constraints\Callback; +use Symfony\Component\Validator\ExecutionContextInterface; use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Translation\Translator; +use Thelia\Model\LangQuery; /** * Class ExportForm @@ -58,6 +61,18 @@ class ExportForm extends BaseForm "label_attr" => ["for" => "with_documents"], "required" => false, )) + ->add("language", "integer", array( + "label" => $this->translator->trans("Language"), + "label_attr" => ["for" => "language"], + "required" => true, + "constraints" => [ + new Callback([ + "methods" => [ + [$this, "checkLanguage"], + ] + ]) + ] + )) ; } @@ -65,4 +80,19 @@ class ExportForm extends BaseForm { return "thelia_export"; } + + public function checkLanguage($value, ExecutionContextInterface $context) + { + if (null === LangQuery::create()->findPk($value)) { + $context->addViolation( + $this->translator->trans( + "The language \"%id\" doesn't exist", + [ + "%id" => $value + ] + ) + ); + } + } + } diff --git a/core/lib/Thelia/Form/ImportForm.php b/core/lib/Thelia/Form/ImportForm.php index b05e736fb..22109a332 100644 --- a/core/lib/Thelia/Form/ImportForm.php +++ b/core/lib/Thelia/Form/ImportForm.php @@ -11,7 +11,11 @@ /*************************************************************************************/ namespace Thelia\Form; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Validator\Constraints\Callback; +use Symfony\Component\Validator\ExecutionContextInterface; use Thelia\Core\Translation\Translator; +use Thelia\Model\LangQuery; /** * Class ImportForm @@ -20,6 +24,17 @@ use Thelia\Core\Translation\Translator; */ class ImportForm extends BaseForm { + /** @var Translator */ + protected $translator; + + public function __construct(Request $request, $type = "form", $data = array(), $options = array()) + { + $this->translator = Translator::getInstance(); + + parent::__construct($request, $type, $data, $options); // TODO: Change the autogenerated stub + } + + /** * * in this function you add all the fields you need for your Form. @@ -42,11 +57,25 @@ class ImportForm extends BaseForm */ protected function buildForm() { - $this->formBuilder->add("file_upload", "file", array( - "label" => Translator::getInstance()->trans("File to upload"), + $this->formBuilder + ->add("file_upload", "file", array( + "label" => $this->translator->trans("File to upload"), "label_attr" => ["for" => "file_to_upload"], "required" => true, - )); + )) + ->add("language", "integer", array( + "label" => $this->translator->trans("Language"), + "label_attr" => ["for" => "language"], + "required" => true, + "constraints" => [ + new Callback([ + "methods" => [ + [$this, "checkLanguage"], + ] + ]) + ] + )) + ; } /** @@ -57,4 +86,18 @@ class ImportForm extends BaseForm return "thelia_import"; } + public function checkLanguage($value, ExecutionContextInterface $context) + { + if (null === LangQuery::create()->findPk($value)) { + $context->addViolation( + $this->translator->trans( + "The language \"%id\" doesn't exist", + [ + "%id" => $value + ] + ) + ); + } + } + } diff --git a/templates/backOffice/default/ajax/export-modal.html b/templates/backOffice/default/ajax/export-modal.html index 18fcf5fd2..178fe2bbf 100644 --- a/templates/backOffice/default/ajax/export-modal.html +++ b/templates/backOffice/default/ajax/export-modal.html @@ -13,7 +13,7 @@