vendor/kunstmaan/node-bundle/EventListener/NodeListener.php line 51

Open in your IDE?
  1. <?php
  2. namespace Kunstmaan\NodeBundle\EventListener;
  3. use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\Tab;
  4. use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionAdmin;
  5. use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMapInterface;
  6. use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
  7. use Kunstmaan\NodeBundle\Event\AdaptFormEvent;
  8. use Kunstmaan\NodeBundle\Helper\FormWidgets\PermissionsFormWidget;
  9. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  10. class NodeListener
  11. {
  12.     /**
  13.      * AuthorizationCheckerInterface
  14.      */
  15.     private $authorizationChecker;
  16.     /**
  17.      * @var PermissionAdmin
  18.      */
  19.     protected $permissionAdmin;
  20.     /**
  21.      * @var PermissionMapInterface
  22.      */
  23.     protected $permissionMap;
  24.     /**
  25.      * @var bool
  26.      */
  27.     private $permissionsEnabled;
  28.     /**
  29.      * @param AuthorizationCheckerInterface $authorizationChecker The security context
  30.      * @param PermissionAdmin               $permissionAdmin      The permission admin
  31.      * @param PermissionMapInterface        $permissionMap        The permission map
  32.      */
  33.     public function __construct(AuthorizationCheckerInterface $authorizationCheckerPermissionAdmin $permissionAdminPermissionMapInterface $permissionMap$permissionsEnabled true)
  34.     {
  35.         $this->authorizationChecker $authorizationChecker;
  36.         $this->permissionAdmin $permissionAdmin;
  37.         $this->permissionMap $permissionMap;
  38.         $this->permissionsEnabled $permissionsEnabled;
  39.     }
  40.     /**
  41.      * @param AdaptFormEvent $event
  42.      */
  43.     public function adaptForm(AdaptFormEvent $event)
  44.     {
  45.         if ($this->permissionsEnabled && $event->getPage() instanceof HasNodeInterface && !$event->getPage()->isStructureNode() && $this->authorizationChecker->isGranted('ROLE_PERMISSIONMANAGER')) {
  46.             $tabPane $event->getTabPane();
  47.             $tabPane->addTab(new Tab('kuma_node.tab.permissions.title', new PermissionsFormWidget($event->getPage(), $event->getNode(), $this->permissionAdmin$this->permissionMap)));
  48.         }
  49.     }
  50. }