src/App/Form/Forms/Security/Profile/ContainerRoleType.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Form\Forms\Security\Profile;
  3. use App\Form\Type\Select2EntityType;
  4. use Cms\ContainerBundle\Doctrine\ContainerRepository;
  5. use Cms\ContainerBundle\Entity\Container;
  6. use Cms\ContainerBundle\Entity\Containers\GenericContainer;
  7. use Cms\ContainerBundle\Entity\Containers\IntranetContainer;
  8. use Common\Util\Strings;
  9. use Platform\SecurityBundle\Entity\Access\Role;
  10. use Symfony\Component\Form\AbstractType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. class ContainerRoleType extends AbstractType
  14. {
  15.     /**
  16.      * {@inheritdoc}
  17.      */
  18.     public function buildForm(FormBuilderInterface $builder, array $options): void
  19.     {
  20.         $builder
  21.             ->add('container'Select2EntityType::class, [
  22.                 'required' => false,
  23.                 'label_tooltip' => true,
  24.                 'placeholder' => '[Global]',
  25.                 'class' => Container::class,
  26.                 'empty_data' => null,
  27.                 'choice_label' => function (Container $choice) {
  28.                     return str_repeat(Strings::nbsp(), ($choice->getLevel() * 4)) . $choice->getName();
  29.                 },
  30.                 'group_by' => function ($val) {
  31.                     if ($val instanceof Container) {
  32.                         switch (true) {
  33.                             case $val instanceof GenericContainer:
  34.                                 return 'Websites';
  35.                             case $val instanceof IntranetContainer:
  36.                                 return 'Intranets';
  37.                             default:
  38.                         }
  39.                     }
  40.                     throw new \LogicException();
  41.                 },
  42.                 'query_builder' => function (ContainerRepository $repo) {
  43.                     return $repo->findAllHierarchyQb(null, [GenericContainer::class, IntranetContainer::class]);
  44.                 },
  45.             ]);
  46.     }
  47.     /**
  48.      * {@inheritdoc}
  49.      */
  50.     public function configureOptions(OptionsResolver $resolver): void
  51.     {
  52.         $resolver->setDefaults([
  53.             'class' => Role\CmsRole::class,
  54.         ]);
  55.     }
  56.     /**
  57.      * {@inheritdoc}
  58.      */
  59.     public function getParent(): string
  60.     {
  61.         return RoleType::class;
  62.     }
  63. }