mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
handle menu with new menuBuilder api
This commit is contained in:
parent
6e8982958e
commit
b0ee67f8b5
@ -52,6 +52,7 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf
|
||||
$loader->load('services/export.yml');
|
||||
$loader->load('services/repositories.yml');
|
||||
$loader->load('services/fixtures.yml');
|
||||
$loader->load('services/menu.yml');
|
||||
}
|
||||
|
||||
public function prepend(ContainerBuilder $container)
|
||||
|
88
Menu/MenuBuilder.php
Normal file
88
Menu/MenuBuilder.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
*/
|
||||
namespace Chill\ActivityBundle\Menu;
|
||||
|
||||
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Knp\Menu\MenuItem;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class MenuBuilder implements LocalMenuBuilderInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TokenStorageInterface
|
||||
*/
|
||||
protected $tokenStorage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
public function __construct(
|
||||
TokenStorageInterface $tokenStorage,
|
||||
TranslatorInterface $translator,
|
||||
AuthorizationHelper $authorizationHelper
|
||||
) {
|
||||
$this->tokenStorage = $tokenStorage;
|
||||
$this->translator = $translator;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
}
|
||||
|
||||
|
||||
public function buildMenu($menuId, MenuItem $menu, array $parameters)
|
||||
{
|
||||
/* @var $person \Chill\PersonBundle\Entity\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' ];
|
||||
}
|
||||
}
|
@ -1,11 +1,6 @@
|
||||
chill_activity_activity_list:
|
||||
path: /{_locale}/person/{person_id}/activity/
|
||||
defaults: { _controller: "ChillActivityBundle:Activity:list" }
|
||||
options:
|
||||
menus:
|
||||
person:
|
||||
order: 201
|
||||
label: Activity list
|
||||
|
||||
chill_activity_activity_show:
|
||||
path: /{_locale}/person/{person_id}/activity/{id}/show
|
||||
@ -14,11 +9,6 @@ chill_activity_activity_show:
|
||||
chill_activity_activity_new:
|
||||
path: /{_locale}/person/{person_id}/activity/new
|
||||
defaults: { _controller: "ChillActivityBundle:Activity:new" }
|
||||
options:
|
||||
menus:
|
||||
person:
|
||||
order: 200
|
||||
label: Add a new activity
|
||||
|
||||
chill_activity_activity_create:
|
||||
path: /{_locale}/person/{person_id}/activity/create
|
||||
|
8
Resources/config/services/menu.yml
Normal file
8
Resources/config/services/menu.yml
Normal file
@ -0,0 +1,8 @@
|
||||
services:
|
||||
Chill\ActivityBundle\Menu\MenuBuilder:
|
||||
arguments:
|
||||
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
||||
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
|
||||
$translator: '@Symfony\Component\Translation\TranslatorInterface'
|
||||
tags:
|
||||
- { name: 'chill.menu_builder' }
|
Loading…
x
Reference in New Issue
Block a user