My client wants a menu with a link for each content type.
- Each item will displayed if the user have permission to create that content type.
- Each item will show a list of content only for that content type.
To accomplish this, I create a view page that have a filter for bundle. In that way I can use same view page for all content types. I tried too, to use same view page like /admin/content but I need to pass the content type to filter for that machine name.
What I trying to do, is create a menu item for each content type, and set permission for each item(link) using the permission that have each content type.
E.g.: My menu have a Item Article. You should see this item only If you have right to create an Article. When you click here you will see all the content Articles(like /admin/content).
It suppose that a user or role, that have permission to create a content type.. should see the item.
How can I create menu items with permission to a view?
There is my issue, because it use the permission in the view page, and not in the route.
.links.menu.yml
content_types.admin_1:
title: 'Articles'
parent: content_types.admin_menu
route_name: content_types.admin_1
route_parameters:
type: article
description: 'Content articles'
content_types.admin_2:
title: 'News'
parent: content_types.admin_menu
route_name: content_types.admin_2
route_parameters:
type: nouvelle
description: 'Content news'
.routing.yml
content_types.admin_1:
path: '/admin/view-test'
defaults:
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
_title: 'Articles'
requirements:
_permission: 'create article content'
content_types.admin_2:
path: '/admin/view-test'
defaults:
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
_title: 'News'
requirements:
_permission: 'create nouvelle content'
As you see I added _permission: 'create article content' but it didn't do anything.
admin/structure/views/view/view_test?destination=/en/admin/structure/views
The role for the user that I'm using doesn't have permission to create article or news.
UPDATED:
I created a .permissions.yml and used _permission: 'access menu item 1' but it display the item even if this permission is not ticket for that role.
.permissions.yml
'access menu item 1':
title: Access Menu MTL 1
description: Allow users to access menu MTL
Any suggestion?
UPDATED: January, 2019
The issue is try to use same view page(/admin/content) for each Content type with different permissions. You dont set permissions to each link, instead you set permission to the view (or item) that you are trying to access.
.permissions.yml
file? Please see kevinquillen.com/drupal/2016/02/21/…