How create Menu items by permissions for a view page? 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.
What I did: 

I tried using dynamic menus. But it isn't functional for my purpose. Because, each link menu could have different access by roles. 

Then I realized that I needed to create a view for each type of content to be able to manage an individual permission.

Therefore I need to create a view each time that I create a CT, so the is no sense to do it dynamically. 

How I did:


I create a view for each CT with a filter content by type. And also I set permission for each view for same CT. And a custom route.

Create one item menu for each CT and set as route same as is in the view.


.links.menu.yml

    vdm.tc_sujet:
     title: 'Sujets'
     parent: system.admin_content
     route_name: vdm.tc_sujets
     description: "Content type subject."
     weight: -1


.routing.yml

    vdm.tc_sujets:
     path: '/admin/content/sujet'
     defaults:
       _controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
       _title: 'Sujets'



As result if user have access to that view the item menu will be displayed.




Note: I think that dynamic menus it fix great for add link item to nodes.