mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 21:13:57 +00:00
fix deprecations: use fqcn instead of 'choices'
This commit is contained in:
@@ -8,25 +8,26 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
|
||||
|
||||
class CustomFieldsGroupType extends AbstractType
|
||||
{
|
||||
|
||||
|
||||
private $customizableEntities; //TOOD : add comment about this variable
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\Translation\TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
|
||||
public function __construct(array $customizableEntities, TranslatorInterface $translator)
|
||||
{
|
||||
$this->customizableEntities = $customizableEntities;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
@@ -37,43 +38,43 @@ class CustomFieldsGroupType extends AbstractType
|
||||
//prepare translation
|
||||
$entities = array();
|
||||
$customizableEntities = array(); //TODO : change name too close than $this->customizableEntities
|
||||
|
||||
|
||||
foreach($this->customizableEntities as $key => $definition) {
|
||||
$entities[$definition['class']] = $this->translator->trans($definition['name']);
|
||||
$customizableEntities[$definition['class']] = $definition;
|
||||
}
|
||||
|
||||
|
||||
$builder
|
||||
->add('name', 'translatable_string')
|
||||
->add('entity', 'choice', array(
|
||||
->add('entity', ChoiceType::class, array(
|
||||
'choices' => $entities
|
||||
))
|
||||
;
|
||||
|
||||
$builder->addEventListener(FormEvents::POST_SET_DATA,
|
||||
$builder->addEventListener(FormEvents::POST_SET_DATA,
|
||||
function(FormEvent $event) use ($customizableEntities, $builder){
|
||||
$form = $event->getForm();
|
||||
$group = $event->getData();
|
||||
|
||||
|
||||
//stop the function if entity is not set
|
||||
if ($group->getEntity() === NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (count($customizableEntities[$group->getEntity()]['options']) > 0) {
|
||||
$optionBuilder = $builder
|
||||
->getFormFactory()
|
||||
->createBuilderForProperty(
|
||||
'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup',
|
||||
'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup',
|
||||
'options'
|
||||
)
|
||||
->create('options', null, array(
|
||||
'compound' => true,
|
||||
'compound' => true,
|
||||
'auto_initialize' => false,
|
||||
'required' => false)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
foreach($customizableEntities[$group->getEntity()]['options'] as $key => $option) {
|
||||
$optionBuilder
|
||||
->add($key, $option['form_type'], $option['form_options'])
|
||||
@@ -82,10 +83,10 @@ class CustomFieldsGroupType extends AbstractType
|
||||
if (isset($optionBuilder) && $optionBuilder->count() > 0) {
|
||||
$form->add($optionBuilder->getForm());
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param OptionsResolverInterface $resolver
|
||||
*/
|
||||
|
@@ -4,10 +4,12 @@ namespace Chill\CustomFieldsBundle\Form\Type;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
|
||||
/**
|
||||
* Return a choice widget with an "other" option
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*
|
||||
*/
|
||||
@@ -24,7 +26,7 @@ class ChoiceWithOtherType extends AbstractType
|
||||
/* (non-PHPdoc)
|
||||
* @see \Symfony\Component\Form\AbstractType::buildForm()
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
//add an 'other' entry in choices array
|
||||
$options['choices']['_other'] = $this->otherValueLabel;
|
||||
@@ -32,17 +34,17 @@ class ChoiceWithOtherType extends AbstractType
|
||||
$options['expanded'] = true;
|
||||
// adding a default value for choice
|
||||
$options['empty_data'] = null;
|
||||
|
||||
|
||||
$builder
|
||||
->add('_other', 'text', array('required' => false))
|
||||
->add('_choices', 'choice', $options)
|
||||
;
|
||||
->add('_other', TextType::class, array('required' => false))
|
||||
->add('_choices', ChoiceType::class, $options)
|
||||
;
|
||||
}
|
||||
|
||||
/* (non-PHPdoc)
|
||||
* @see \Symfony\Component\Form\AbstractType::configureOptions()
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setRequired(array('choices'))
|
||||
@@ -57,4 +59,4 @@ class ChoiceWithOtherType extends AbstractType
|
||||
{
|
||||
return 'choice_with_other';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user