security = $security; $this->voterHelper = $voterHelperFactory ->generate(self::class) ->addCheckFor(null, [self::CREATE]) ->addCheckFor(AccompanyingPeriod::class, self::ALL) ->addCheckFor(Person::class, [self::SEE]) ->build(); } protected function supports($attribute, $subject) { return $this->voterHelper->supports($attribute, $subject); } protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool { if (!$token->getUser() instanceof User) { return false; } if ($subject instanceof AccompanyingPeriod) { if (AccompanyingPeriod::STEP_DRAFT === $subject->getStep()) { // only creator can see, edit, delete, etc. if ($subject->getCreatedBy() === $token->getUser() || NULL === $subject->getCreatedBy()) { return true; } return false; } // if confidential, only the referent can see it if ($subject->isConfidential()) { return $token->getUser() === $subject->getUser(); } } return $this->voterHelper->voteOnAttribute($attribute, $subject, $token); } public function getRoles() { return self::ALL; } public function getRolesWithoutScope() { return []; } public function getRolesWithHierarchy() { return [ 'Accompanying period' => $this->getRoles() ]; } }