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

@@ -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
]
)
);
}
}
}

View File

@@ -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
]
)
);
}
}
}