Form/Type/AppendScopeChoiceTypeTrait.php
protected function appendScopeChoices(FormBuilderInterface $builder, 
            Role $role, Center $center, User $user,
            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, 
                function (FormEvent $event) use ($choices, $name, $dataTransformer, $builder) {
                    $form = $event->getForm();
                    $form->add(
                            $builder
                            ->create($name, 'choice', array(
                                'choices' => $choices,
                                'auto_initialize' => false
                                )
                            )
                            ->addModelTransformer($dataTransformer)
                            ->getForm()
                    );
                });
    }
protected function appendScopeChoices(FormBuilderInterface $builder, 
            Role $role, Center $center, User $user,
            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, 
                function (FormEvent $event) use ($choices, $name, $dataTransformer, $builder) {
                    $form = $event->getForm();
                    $form->add(
                            $builder
                            ->create($name, 'choice', array(
                                'choices' => $choices,
                                'auto_initialize' => false
                                )
                            )
                            ->addModelTransformer($dataTransformer)
                            ->getForm()
                    );
                });
    }
protected function appendScopeChoices ( FormBuilderInterface $ builder , Role $ role , Center $ center , User $ user , 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 , function ( FormEvent $ event ) use ( $ choices , $ name , $ dataTransformer , $ builder ) { $ form = $ event -> getForm ( ) ; $ form -> add ( $ builder -> create ( $ name , 'choice' , array ( 'choices' => $ choices , 'auto_initialize' => false ) ) -> addModelTransformer ( $ dataTransformer ) -> getForm ( ) ) ; } ) ; }
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
@param User $user
@param AuthorizationHelper $authorizationHelper
@param TranslatableStringHelper $translatableStringHelper
@param string $name
Append a scope choice field with the scopes reachable by given user for the given role and center .