diff --git a/CustomFields/CustomFieldChoice.php b/CustomFields/CustomFieldChoice.php index 81e57df87..6caf4b130 100644 --- a/CustomFields/CustomFieldChoice.php +++ b/CustomFields/CustomFieldChoice.php @@ -32,6 +32,7 @@ use Symfony\Bridge\Twig\TwigEngine; use Chill\MainBundle\Templating\TranslatableStringHelper; use Symfony\Component\Translation\Translator; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Chill\MainBundle\Form\Type\TranslatableStringFormType; /** * @@ -151,7 +152,7 @@ class CustomFieldChoice extends AbstractCustomField 'expanded' => true, 'multiple' => false )) - ->add(self::OTHER_VALUE_LABEL, 'translatable_string', array( + ->add(self::OTHER_VALUE_LABEL, TranslatableStringFormType::class, array( 'label' => 'Other value label (empty if use by default)')) ->add(self::CHOICES, new ChoicesType(), array( 'type' => new ChoicesListType($this->defaultLocales), diff --git a/Form/CustomFieldType.php b/Form/CustomFieldType.php index ba7710cbf..db6191e7c 100644 --- a/Form/CustomFieldType.php +++ b/Form/CustomFieldType.php @@ -15,6 +15,7 @@ use Symfony\Component\Form\FormEvents; use Doctrine\Common\Persistence\ObjectManager; use Chill\CustomFieldsBundle\Service\CustomFieldProvider; use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer; +use Chill\MainBundle\Form\Type\TranslatableStringFormType; class CustomFieldType extends AbstractType @@ -53,7 +54,7 @@ class CustomFieldType extends AbstractType } $builder - ->add('name', 'translatable_string') + ->add('name', TranslatableStringFormType::class) ->add('active', CheckboxType::class, array('required' => false)); if ($options['group_widget'] === 'entity') { diff --git a/Form/Type/ChoicesListType.php b/Form/Type/ChoicesListType.php index 120559920..c272834c8 100644 --- a/Form/Type/ChoicesListType.php +++ b/Form/Type/ChoicesListType.php @@ -6,11 +6,13 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; +use Chill\MainBundle\Form\Type\TranslatableStringFormType; + class ChoicesListType extends AbstractType { - + private $defaultLocales; - + public function __construct($defaultLocales) { $this->defaultLocales = $defaultLocales; @@ -22,26 +24,26 @@ class ChoicesListType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $locales = $this->defaultLocales; - - $builder->add('name', 'translatable_string') + + $builder->add('name', TranslatableStringFormType::class) ->add('active', 'checkbox', array( 'required' => false )) ->add('slug', 'hidden', array( - + )) ->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) use ($locales){ $form = $event->getForm(); $data = $event->getData(); $formData = $form->getData(); - + if (NULL === $formData['slug']) { $slug = $form['name'][$locales[0]]->getData(); $slug = strtolower($slug); $slug = preg_replace('/[^a-zA-Z0-9 -]/','', $slug); // only take alphanumerical characters, but keep the spaces and dashes too... $slug = str_replace(' ','-', $slug); // replace spaces by dashes - + $data['slug'] = $slug; $event->setData($data); } else { @@ -51,8 +53,8 @@ class ChoicesListType extends AbstractType }) ; } - - + + /* * * @see \Symfony\Component\Form\FormTypeInterface::getName()