voterHelper = $voterHelperFactory ->generate(self::class) ->addCheckFor(null, [self::SEE]) ->addCheckFor(Participation::class, [...self::ROLES]) ->addCheckFor(Person::class, [self::SEE, self::CREATE]) ->addCheckFor(Center::class, [self::STATS]) ->build(); } public function getRoles(): array { return [...self::ROLES, self::STATS]; } public function getRolesWithHierarchy(): array { return [ 'Participation' => $this->getRoles(), ]; } public function getRolesWithoutScope(): array { return []; } public function supports($attribute, $subject) { return $this->voterHelper->supports($attribute, $subject); } /** * @param string $attribute * * @return bool */ protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { $this->logger->debug(sprintf('Voting from %s class', self::class)); if (!$token->getUser() instanceof User) { return false; } if ($subject instanceof Participation) { return $this->authorizationHelper->userHasAccess($token->getUser(), $subject, $attribute); } if ($subject instanceof Person) { return $this->authorizationHelper->userHasAccess($token->getUser(), $subject, $attribute); } // subject is null. We check that at least one center is reachable $centers = $this->authorizationHelper ->getReachableCenters($token->getUser(), $attribute); return \count($centers) > 0; } }