security = $security; $this->voterHelper = $voterHelperFactory ->generate(self::class) ->addCheckFor(AccompanyingPeriod::class, [self::SEE]) ->build(); } public function getRolesWithHierarchy(): array { return ['Calendar' => $this->getRoles()]; } public function getRoles(): array { return [ self::SEE, ]; } public function getRolesWithoutScope(): array { return []; } protected function supports($attribute, $subject): bool { return $this->voterHelper->supports($attribute, $subject); } protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool { if ($subject instanceof AccompanyingPeriod) { switch ($attribute) { case self::SEE: if ($subject->getStep() === AccompanyingPeriod::STEP_DRAFT) { return false; } // we first check here that the user has read access to the period return $this->security->isGranted(AccompanyingPeriodVoter::SEE, $subject); default: throw new \LogicException('subject not implemented'); } } throw new \LogicException('attribute not implemented'); } }