mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
fix deprecations: use fcqn instead of 'choice'
This commit is contained in:
parent
def1b1c01f
commit
9951a5d765
@ -26,11 +26,12 @@ use Symfony\Component\Form\FormEvents;
|
|||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This type create a Choice field with custom fields as choices.
|
* This type create a Choice field with custom fields as choices.
|
||||||
*
|
*
|
||||||
* This type can only be associated with a customFieldsGroup type. The field
|
* This type can only be associated with a customFieldsGroup type. The field
|
||||||
* is populated when the data (a customFieldsGroup entity) is associated with
|
* is populated when the data (a customFieldsGroup entity) is associated with
|
||||||
* the form
|
* the form
|
||||||
*
|
*
|
||||||
@ -43,51 +44,51 @@ class LinkedCustomFieldsType extends AbstractType
|
|||||||
* @var TranslatableStringHelper
|
* @var TranslatableStringHelper
|
||||||
*/
|
*/
|
||||||
private $translatableStringHelper;
|
private $translatableStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name for the choice field
|
* The name for the choice field
|
||||||
*
|
*
|
||||||
* Extracted from builder::getName
|
* Extracted from builder::getName
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $choiceName = 'choice';
|
private $choiceName = 'choice';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the option of the form.
|
* the option of the form.
|
||||||
*
|
*
|
||||||
* @internal options are stored at the class level to be reused by appendChoice, after data are setted
|
* @internal options are stored at the class level to be reused by appendChoice, after data are setted
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $options = array();
|
private $options = array();
|
||||||
|
|
||||||
public function __construct(TranslatableStringHelper $helper)
|
public function __construct(TranslatableStringHelper $helper)
|
||||||
{
|
{
|
||||||
$this->translatableStringHelper = $helper;
|
$this->translatableStringHelper = $helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$this->choiceName = $builder->getName();
|
$this->choiceName = $builder->getName();
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
|
|
||||||
$builder->addEventListener(FormEvents::POST_SET_DATA,
|
$builder->addEventListener(FormEvents::POST_SET_DATA,
|
||||||
array($this, 'appendChoice'))
|
array($this, 'appendChoice'))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getParent()
|
public function getParent()
|
||||||
{
|
{
|
||||||
return 'choice';
|
return 'choice';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* append Choice on POST_SET_DATA event
|
* append Choice on POST_SET_DATA event
|
||||||
*
|
*
|
||||||
* Choices are extracted from custom_field_group (the data associated
|
* Choices are extracted from custom_field_group (the data associated
|
||||||
* with the root form)
|
* with the root form)
|
||||||
*
|
*
|
||||||
* @param FormEvent $event
|
* @param FormEvent $event
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -95,29 +96,29 @@ class LinkedCustomFieldsType extends AbstractType
|
|||||||
{
|
{
|
||||||
$rootForm = $this->getRootForm($event->getForm());
|
$rootForm = $this->getRootForm($event->getForm());
|
||||||
$group = $rootForm->getData();
|
$group = $rootForm->getData();
|
||||||
|
|
||||||
if ($group === NULL) {
|
if ($group === NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$choices = array();
|
$choices = array();
|
||||||
foreach($group->getCustomFields() as $customFields) {
|
foreach($group->getCustomFields() as $customFields) {
|
||||||
$choices[$customFields->getSlug()] =
|
$choices[$customFields->getSlug()] =
|
||||||
$this->translatableStringHelper
|
$this->translatableStringHelper
|
||||||
->localize($customFields->getName());
|
->localize($customFields->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array_merge($this->options, array(
|
$options = array_merge($this->options, array(
|
||||||
'choice_list' => new SimpleChoiceList($choices),
|
'choice_list' => new SimpleChoiceList($choices),
|
||||||
));
|
));
|
||||||
|
|
||||||
$event->getForm()->getParent()->add($this->choiceName, 'choice',
|
$event->getForm()->getParent()->add($this->choiceName, ChoiceType::class,
|
||||||
$options);
|
$options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the root form (i.e. produced from CustomFieldsGroupType::getForm)
|
* Return the root form (i.e. produced from CustomFieldsGroupType::getForm)
|
||||||
*
|
*
|
||||||
* @param FormInterface $form
|
* @param FormInterface $form
|
||||||
* @return FormInterface
|
* @return FormInterface
|
||||||
*/
|
*/
|
||||||
@ -129,7 +130,7 @@ class LinkedCustomFieldsType extends AbstractType
|
|||||||
return $this->getRootForm($form->getParent());
|
return $this->getRootForm($form->getParent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'custom_fields_group_linked_custom_fields';
|
return 'custom_fields_group_linked_custom_fields';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user