src/Security/Voter/PageBlockTranslationLogoThumbVoter.php line 13

  1. <?php
  2. namespace App\Security\Voter;
  3. use Symfony\Component\Security\Core\Authorization\Voter\Voter,
  4.     Symfony\Component\Security\Core\Authentication\Token\TokenInterface,
  5.     Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  6. use App\Entity\Page,
  7.     App\Entity\PageBlockTranslationLogoThumb,
  8.     App\Lib\Actions,
  9.     App\Lib\Roles;
  10. final class PageBlockTranslationLogoThumbVoter extends Voter
  11. {
  12.     private AuthorizationCheckerInterface $authorizationChecker;
  13.     public function __construct(AuthorizationCheckerInterface $authorizationChecker)
  14.     {
  15.         $this->authorizationChecker $authorizationChecker;
  16.     }
  17.     protected function supports($attribute$subject): bool
  18.     {
  19.         if (! $subject instanceof PageBlockTranslationLogoThumb) {
  20.             return false;
  21.         }
  22.         return true;
  23.     }
  24.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  25.     {
  26.         if ($this->authorizationChecker->isGranted(Roles::ROLE_OPENFORM)) {
  27.             return true;
  28.         }
  29.         /** @var Page */
  30.         $page $subject
  31.             ->getParent()
  32.             ->getParent()
  33.             ->getParent()
  34.             ->getParent();
  35.         return match($attribute) {
  36.             Actions::EDIT => $page->getIsEditable(),
  37.             default => false,
  38.         };
  39.     }
  40. }