src/Security/Voter/JournalPageVoter.php line 12
<?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\JournalPage,
App\Lib\Actions,
App\Lib\Roles;
final class JournalPageVoter extends Voter
{
const MESSAGE = 'Predefined page cannot be deleted.';
private AuthorizationCheckerInterface $authorizationChecker;
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker = $authorizationChecker;
}
protected function supports($attribute, $subject): bool
{
if (! $subject instanceof JournalPage || Actions::DELETE !== $attribute) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
if ($this->authorizationChecker->isGranted(Roles::ROLE_OPENFORM)) {
return true;
}
if ($subject->getIdName()) {
return false;
}
return true;
}
}