diff --git a/CustomFields/CustomFieldChoice.php b/CustomFields/CustomFieldChoice.php index e89f70c5b..927bd3ead 100644 --- a/CustomFields/CustomFieldChoice.php +++ b/CustomFields/CustomFieldChoice.php @@ -157,7 +157,7 @@ class CustomFieldChoice extends AbstractCustomField ->add(self::OTHER_VALUE_LABEL, TranslatableStringFormType::class, array( 'label' => 'Other value label (empty if use by default)')) ->add(self::CHOICES, ChoicesType::class, array( - 'entry_type' => new ChoicesListType($this->defaultLocales), + 'entry_type' => ChoicesListType::class, 'allow_add' => true )); diff --git a/Form/Type/ChoicesListType.php b/Form/Type/ChoicesListType.php index a0b3d2d87..7d8457783 100644 --- a/Form/Type/ChoicesListType.php +++ b/Form/Type/ChoicesListType.php @@ -13,38 +13,24 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType; class ChoicesListType extends AbstractType { - private $defaultLocales; - - public function __construct($defaultLocales) - { - $this->defaultLocales = $defaultLocales; - } - /* (non-PHPdoc) * @see \Symfony\Component\Form\AbstractType::buildForm() */ public function buildForm(FormBuilderInterface $builder, array $options) { - $locales = $this->defaultLocales; - $builder->add('name', TranslatableStringFormType::class) ->add('active', CheckboxType::class, array( 'required' => false )) - ->add('slug', HiddenType::class, array( - - )) - ->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) use ($locales){ + ->add('slug', HiddenType::class) + ->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) { $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 + $slug = uniqid(rand(), true); $data['slug'] = $slug; $event->setData($data); diff --git a/Resources/views/Form/fields.html.twig b/Resources/views/Form/fields.html.twig index b25ec65cd..1fc722d77 100644 --- a/Resources/views/Form/fields.html.twig +++ b/Resources/views/Form/fields.html.twig @@ -52,9 +52,9 @@ {# we use javascrit to add an additional element. All functions are personnalized with the id ( = form.vars.id) #}