fix deprecations: use fqcn fr translatable_string

This commit is contained in:
nobohan 2018-04-05 13:59:14 +02:00
parent 762bb777c3
commit d501fa31ae
3 changed files with 15 additions and 11 deletions

View File

@ -32,6 +32,7 @@ use Symfony\Bridge\Twig\TwigEngine;
use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\Translator;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
/** /**
* *
@ -151,7 +152,7 @@ class CustomFieldChoice extends AbstractCustomField
'expanded' => true, 'expanded' => true,
'multiple' => false '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)')) 'label' => 'Other value label (empty if use by default)'))
->add(self::CHOICES, new ChoicesType(), array( ->add(self::CHOICES, new ChoicesType(), array(
'type' => new ChoicesListType($this->defaultLocales), 'type' => new ChoicesListType($this->defaultLocales),

View File

@ -15,6 +15,7 @@ use Symfony\Component\Form\FormEvents;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider; use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer; use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
class CustomFieldType extends AbstractType class CustomFieldType extends AbstractType
@ -53,7 +54,7 @@ class CustomFieldType extends AbstractType
} }
$builder $builder
->add('name', 'translatable_string') ->add('name', TranslatableStringFormType::class)
->add('active', CheckboxType::class, array('required' => false)); ->add('active', CheckboxType::class, array('required' => false));
if ($options['group_widget'] === 'entity') { if ($options['group_widget'] === 'entity') {

View File

@ -6,11 +6,13 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
class ChoicesListType extends AbstractType class ChoicesListType extends AbstractType
{ {
private $defaultLocales; private $defaultLocales;
public function __construct($defaultLocales) public function __construct($defaultLocales)
{ {
$this->defaultLocales = $defaultLocales; $this->defaultLocales = $defaultLocales;
@ -22,26 +24,26 @@ class ChoicesListType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$locales = $this->defaultLocales; $locales = $this->defaultLocales;
$builder->add('name', 'translatable_string') $builder->add('name', TranslatableStringFormType::class)
->add('active', 'checkbox', array( ->add('active', 'checkbox', array(
'required' => false 'required' => false
)) ))
->add('slug', 'hidden', array( ->add('slug', 'hidden', array(
)) ))
->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) use ($locales){ ->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) use ($locales){
$form = $event->getForm(); $form = $event->getForm();
$data = $event->getData(); $data = $event->getData();
$formData = $form->getData(); $formData = $form->getData();
if (NULL === $formData['slug']) { if (NULL === $formData['slug']) {
$slug = $form['name'][$locales[0]]->getData(); $slug = $form['name'][$locales[0]]->getData();
$slug = strtolower($slug); $slug = strtolower($slug);
$slug = preg_replace('/[^a-zA-Z0-9 -]/','', $slug); // only take alphanumerical characters, but keep the spaces and dashes too... $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 = str_replace(' ','-', $slug); // replace spaces by dashes
$data['slug'] = $slug; $data['slug'] = $slug;
$event->setData($data); $event->setData($data);
} else { } else {
@ -51,8 +53,8 @@ class ChoicesListType extends AbstractType
}) })
; ;
} }
/* /*
* *
* @see \Symfony\Component\Form\FormTypeInterface::getName() * @see \Symfony\Component\Form\FormTypeInterface::getName()