tokenStorage = $tokenStorage; $this->translator = $translator; $this->authorizationHelper = $authorizationHelper; } public function buildMenu($menuId, MenuItem $menu, array $parameters) { /** @var \Chill\PersonBundle\Entity\Person $person */ $person = $parameters['person']; $user = $this->tokenStorage->getToken()->getUser(); $roleSee = new Role(ActivityVoter::SEE); $roleAdd = new Role(ActivityVoter::CREATE); if ($this->authorizationHelper->userHasAccess($user, $person, $roleSee)) { $menu->addChild($this->translator->trans('Activity list'), [ 'route' => 'chill_activity_activity_list', 'routeParameters' => [ 'person_id' => $person->getId(), ], ]) ->setExtras([ 'order' => 201, ]); } if ($this->authorizationHelper->userHasAccess($user, $person, $roleAdd)) { $menu->addChild($this->translator->trans('Add a new activity'), [ 'route' => 'chill_activity_activity_new', 'routeParameters' => [ 'person_id' => $person->getId(), ], ]) ->setExtras([ 'order' => 200, ]); } } public static function getMenuIds(): array { return ['person']; } }