mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 19:13:49 +00:00
fix: SA: Fix "might not be defined" rule.
SA stands for Static Analysis.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Form;
|
||||
|
||||
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
@@ -15,7 +16,7 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
class CustomFieldsGroupType extends AbstractType
|
||||
{
|
||||
|
||||
|
||||
|
||||
private $customizableEntities; //TODO : add comment about this variable
|
||||
|
||||
/**
|
||||
@@ -52,50 +53,48 @@ class CustomFieldsGroupType extends AbstractType
|
||||
))
|
||||
;
|
||||
|
||||
$builder->addEventListener(FormEvents::POST_SET_DATA,
|
||||
function(FormEvent $event) use ($customizableEntities, $builder){
|
||||
$form = $event->getForm();
|
||||
$group = $event->getData();
|
||||
$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;
|
||||
}
|
||||
//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',
|
||||
'options'
|
||||
)
|
||||
->create('options', null, array(
|
||||
'compound' => true,
|
||||
'auto_initialize' => false,
|
||||
'required' => false)
|
||||
);
|
||||
}
|
||||
$optionBuilder = null;
|
||||
if (count($customizableEntities[$group->getEntity()]['options']) > 0) {
|
||||
$optionBuilder = $builder
|
||||
->getFormFactory()
|
||||
->createBuilderForProperty(CustomFieldsGroup::class, 'options')
|
||||
->create(
|
||||
'options',
|
||||
null,
|
||||
[
|
||||
'compound' => true,
|
||||
'auto_initialize' => false,
|
||||
'required' => false
|
||||
]
|
||||
);
|
||||
|
||||
foreach($customizableEntities[$group->getEntity()]['options'] as $key => $option) {
|
||||
$optionBuilder
|
||||
->add($key, $option['form_type'], $option['form_options'])
|
||||
;
|
||||
}
|
||||
if (isset($optionBuilder) && $optionBuilder->count() > 0) {
|
||||
$form->add($optionBuilder->getForm());
|
||||
$optionBuilder->add($key, $option['form_type'], $option['form_options']);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
if ((null !== $optionBuilder) && $optionBuilder->count() > 0) {
|
||||
$form->add($optionBuilder->getForm());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolverInterface $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup'
|
||||
));
|
||||
$resolver->setDefaults([
|
||||
'data_class' => CustomFieldsGroup::class,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user