fix deprecations: use the fqcn for choiceType

This commit is contained in:
nobohan
2018-04-04 10:29:57 +02:00
parent c4f7256236
commit 56a695e66e
6 changed files with 269 additions and 268 deletions

View File

@@ -34,9 +34,9 @@ use Chill\MainBundle\Form\Type\DataTransformer\ScopeTransformer;
/**
* Trait to add an input with reachable scope for a given center and role.
*
*
* Example usage :
*
*
* ```
* class AbcType extends Symfony\Component\Form\AbstractType
* {
@@ -45,9 +45,9 @@ use Chill\MainBundle\Form\Type\DataTransformer\ScopeTransformer;
* protected $translatableStringHelper;
* protected $user;
* protected $om;
*
*
* public function __construct(AuthorizationHelper $helper,
* TokenStorageInterface $tokenStorage,
* TokenStorageInterface $tokenStorage,
* TranslatableStringHelper $translatableStringHelper,
* ObjectManager $om)
* {
@@ -56,39 +56,39 @@ use Chill\MainBundle\Form\Type\DataTransformer\ScopeTransformer;
* $this->translatableStringHelper = $translatableStringHelper;
* $this->om = $om;
* }
*
*
* public function buildForm(FormBuilder $builder, array $options)
* {
* // ... add your form there
*
*
* // append the scope using FormEvents: PRE_SET_DATA
* $this->appendScopeChoices($builder, $options['role'],
* $options['center'], $this->user, $this->authorizationHelper,
* $this->appendScopeChoices($builder, $options['role'],
* $options['center'], $this->user, $this->authorizationHelper,
* $this->translatableStringHelper, $this->om);
* }
*
*
* public function configureOptions(OptionsResolver $resolver)
* {
* // ... add your options
*
*
* // add an option 'role' and 'center' to your form (optional)
* $this->appendScopeChoicesOptions($resolver);
* }
*
*
* }
* ```
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop>
*/
trait AppendScopeChoiceTypeTrait
trait AppendScopeChoiceTypeTrait
{
/**
* Append a scope choice field, with the scopes reachable by given
* user for the given role and center.
*
*
* The field is added on event FormEvents::PRE_SET_DATA
*
*
* @param FormBuilderInterface $builder
* @param Role $role
* @param Center $center
@@ -97,29 +97,29 @@ trait AppendScopeChoiceTypeTrait
* @param TranslatableStringHelper $translatableStringHelper
* @param string $name
*/
protected function appendScopeChoices(FormBuilderInterface $builder,
protected function appendScopeChoices(FormBuilderInterface $builder,
Role $role, Center $center, User $user,
AuthorizationHelper $authorizationHelper,
AuthorizationHelper $authorizationHelper,
TranslatableStringHelper $translatableStringHelper,
ObjectManager $om, $name = 'scope')
{
$reachableScopes = $authorizationHelper
->getReachableScopes($user, $role, $center);
$choices = array();
foreach($reachableScopes as $scope) {
$choices[$scope->getId()] = $translatableStringHelper
->localize($scope->getName());
}
$dataTransformer = new ScopeTransformer($om);
$builder->addEventListener(FormEvents::PRE_SET_DATA,
$builder->addEventListener(FormEvents::PRE_SET_DATA,
function (FormEvent $event) use ($choices, $name, $dataTransformer, $builder) {
$form = $event->getForm();
$form->add(
$builder
->create($name, 'choice', array(
->create($name, ChoiceType::class, array(
'choices' => $choices,
'auto_initialize' => false
)
@@ -129,14 +129,14 @@ trait AppendScopeChoiceTypeTrait
);
});
}
/**
* Append a `role` and `center` option to the form.
*
* The allowed types are :
*
* The allowed types are :
* - Chill\MainBundle\Entity\Center for center
* - Symfony\Component\Security\Core\Role\Role for role
*
*
* @param OptionsResolver $resolver
*/
public function appendScopeChoicesOptions(OptionsResolver $resolver)
@@ -149,5 +149,5 @@ trait AppendScopeChoiceTypeTrait
))
;
}
}

View File

@@ -85,7 +85,7 @@ class ComposedRoleScopeType extends AbstractType
}
$builder
->add('role', 'choice', array(
->add('role', ChoiceType::class, array(
'choices' => $values,
'placeholder' => 'Choose amongst roles',
'choice_attr' => function($role) use ($rolesWithoutScopes) {
@@ -109,7 +109,7 @@ class ComposedRoleScopeType extends AbstractType
));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('data_class', 'Chill\MainBundle\Entity\RoleScope');

View File

@@ -26,43 +26,43 @@ use Chill\MainBundle\Export\ExportManager;
/**
* Choose a formatter amongst the available formatters
*
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class PickFormatterType extends AbstractType
{
protected $exportManager;
public function __construct(ExportManager $exportManager)
{
$this->exportManager = $exportManager;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$export = $this->exportManager->getExport($options['export_alias']);
$allowedFormatters = $this->exportManager
->getFormattersByTypes($export->getAllowedFormattersTypes());
//build choices
$choices = array();
foreach($allowedFormatters as $alias => $formatter) {
$choices[$formatter->getName()] = $alias;
}
$builder->add('alias', 'choice', array(
$builder->add('alias', ChoiceType::class, array(
'choices' => $choices,
'choices_as_values' => true,
'multiple' => false
));
//$builder->get('type')->addModelTransformer($transformer);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(array('export_alias'));
}
}

View File

@@ -5,6 +5,7 @@ namespace Chill\MainBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Chill\MainBundle\Form\UserPasswordType;
class UserType extends AbstractType
@@ -25,7 +26,7 @@ class UserType extends AbstractType
} else {
$builder->add($builder
->create('enabled', 'choice', array(
->create('enabled', ChoiceType::class, array(
'choices' => array(
0 => 'Disabled, the user is not allowed to login',
1 => 'Enabled, the user is active'