src/Security/Voter/PageBlockTranslationThumbVoter.php line 13
<?php
namespace App\Security\Voter;
use Symfony\Component\Security\Core\Authorization\Voter\Voter,
Symfony\Component\Security\Core\Authentication\Token\TokenInterface,
Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use App\Entity\Page,
App\Entity\PageBlockTranslationThumb,
App\Lib\Actions,
App\Lib\Roles;
final class PageBlockTranslationThumbVoter extends Voter
{
private AuthorizationCheckerInterface $authorizationChecker;
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker = $authorizationChecker;
}
protected function supports($attribute, $subject): bool
{
if (! $subject instanceof PageBlockTranslationThumb) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
if ($this->authorizationChecker->isGranted(Roles::ROLE_OPENFORM)) {
return true;
}
/** @var Page */
$page = $subject
->getParent()
->getParent()
->getParent();
return match($attribute) {
Actions::EDIT => $page->getIsEditable(),
default => false,
};
}
}