From a57d668e3cdbbb2aa517bed09ef30bab0edd6b5c Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 4 Jul 2014 11:54:02 +0200 Subject: [PATCH] Improved brand form declarations --- .../Thelia/Form/Brand/BrandCreationForm.php | 88 ++++++++++--------- .../Form/Brand/BrandModificationForm.php | 53 ++++------- templates/backOffice/default/brands.html | 2 +- 3 files changed, 66 insertions(+), 77 deletions(-) diff --git a/core/lib/Thelia/Form/Brand/BrandCreationForm.php b/core/lib/Thelia/Form/Brand/BrandCreationForm.php index 88977dc5c..57c00dbdc 100644 --- a/core/lib/Thelia/Form/Brand/BrandCreationForm.php +++ b/core/lib/Thelia/Form/Brand/BrandCreationForm.php @@ -25,51 +25,55 @@ use Thelia\Model\Lang; */ class BrandCreationForm extends BaseForm { + protected function doBuilForm($titleFieldHelpLabel) + { + $this->formBuilder->add( + 'title', + 'text', + [ + 'constraints' => [ new NotBlank() ], + 'required' => true, + 'label' => Translator::getInstance()->trans('Brand name'), + 'label_attr' => [ + 'for' => 'title', + 'help' => $titleFieldHelpLabel + ], + 'attr' => [ + 'placeholder' => Translator::getInstance()->trans('The brand name or title'), + ] + ] + ) + ->add( + 'locale', + 'hidden', + [ + 'constraints' => [ new NotBlank() ], + 'required' => true, + ] + ) + // Is this brand online ? + ->add( + 'visible', + 'checkbox', + [ + 'constraints' => [ ], + 'required' => false, + 'label' => Translator::getInstance()->trans('This brand is online'), + 'label_attr' => [ + 'for' => 'visible_create' + ] + ] + ); + } + protected function buildForm() { - $this->formBuilder - // Brand title - ->add( - 'title', - 'text', - [ - 'constraints' => [ new NotBlank() ], - 'required' => true, - 'label' => Translator::getInstance()->trans('Brand name'), - 'label_attr' => [ - 'for' => 'title', - 'help' => Translator::getInstance()->trans( - 'Enter here the brand name in the default language (%title%)', - [ '%title%' => Lang::getDefaultLanguage()->getTitle()] - ), - ], - 'attr' => [ - 'placeholder' => Translator::getInstance()->trans('The brand name or title'), - ] - ] + $this->doBuilForm( + Translator::getInstance()->trans( + 'Enter here the brand name in the default language (%title%)', + [ '%title%' => Lang::getDefaultLanguage()->getTitle()] ) - // Current locale - ->add( - 'locale', - 'hidden', - [ - 'constraints' => [ new NotBlank() ], - 'required' => true, - ] - ) - // Is this brand online ? - ->add( - 'visible', - 'checkbox', - [ - 'constraints' => [ ], - 'required' => true, - 'label' => Translator::getInstance()->trans('This brand is online'), - 'label_attr' => [ - 'for' => 'visible_create' - ] - ] - ); + ); } public function getName() diff --git a/core/lib/Thelia/Form/Brand/BrandModificationForm.php b/core/lib/Thelia/Form/Brand/BrandModificationForm.php index 9d96a5b4b..c4f1ce16f 100644 --- a/core/lib/Thelia/Form/Brand/BrandModificationForm.php +++ b/core/lib/Thelia/Form/Brand/BrandModificationForm.php @@ -28,42 +28,27 @@ class BrandModificationForm extends BrandCreationForm protected function buildForm() { - parent::buildForm(); + $this->doBuilForm( + Translator::getInstance()->trans('The brand name or title') + ); - $this->formBuilder - ->add( - 'id', - 'hidden', - [ - 'constraints' => [ new GreaterThan(['value' => 0]) ], - 'required' => true, + $this->formBuilder->add( + 'id', + 'hidden', + [ + 'constraints' => [ new GreaterThan(['value' => 0]) ], + 'required' => true, + ] + ) + ->add("logo_image_id", "integer", [ + 'constraints' => [ ], + 'required' => false, + 'label' => Translator::getInstance()->trans('Select the brand logo'), + 'label_attr' => [ + 'for' => 'mode', + 'help' => Translator::getInstance()->trans("Select the brand logo amongst the brand images") ] - ) - // Brand title - ->add( - 'title', - 'text', - [ - 'constraints' => [ new NotBlank() ], - 'required' => true, - 'label' => Translator::getInstance()->trans('Brand name'), - 'label_attr' => [ - 'for' => 'title' - ], - 'attr' => [ - 'placeholder' => Translator::getInstance()->trans('The brand name or title') - ] - ] - ) - ->add("logo_image_id", "integer", [ - 'constraints' => [ ], - 'required' => false, - 'label' => Translator::getInstance()->trans('Select the brand logo'), - 'label_attr' => [ - 'for' => 'mode', - 'help' => Translator::getInstance()->trans("Select the brand logo amongst the brand images") - ] - ]) + ]) ; // Add standard description fields, excluding title and locale, which are already defined diff --git a/templates/backOffice/default/brands.html b/templates/backOffice/default/brands.html index 290095252..a0c1a224e 100644 --- a/templates/backOffice/default/brands.html +++ b/templates/backOffice/default/brands.html @@ -200,7 +200,7 @@ {* Switch edition to the current locale *} - {render_form_field field="locale" value=$LOCALE} + {render_form_field form=$form field="locale" value=$LOCALE}