Adding action links to pages in Drupal 8
To add an action link for creating content of a given node type on a related listing view, you could add to 'example' module an example.links.action.yml file with contents like the following:
example.add_resource:
route_name: 'node.add'
route_parameters:
node_type: 'resource'
title: 'Add resource'
appears_on:
- view.search_resources_content.page_1
drupal 8 action links on dynamic routes
links.action.yml appears_on dynamic
To put an action link on an arbitrary node page, you'll need to get the route for that node. You can't do drupal router:debug | grep '/my-alias' nor even drupal router:debug | grep '/node/8' — console is only providing the real routes, not the (literally infinite) paths that can be created by these routes.
If you do:
drupal router:debug | grep '/node/'
You'll note it returns the route:
entity.node.canonical
For:
/node/{node}
You cannot use a yaml file to put an action link on a dynamic path, on a route name only when given a parameter, such as a particular node.
https://www.drupal.org/node/2499819#comment-11791002
Resources:
How do I create a link to add a specific content type
https://www.drupal.org/node/2374343
Create an "add content" link in View Header that is only visible to users with appropriate permissions. [Solved]
https://www.drupal.org/node/2006322
Add link to add content to views lists
https://www.drupal.org/node/2104553
Add action link to view
https://www.drupal.org/node/1313132
See also:
https://thinkshout.com/blog/2016/07/drupal-8-routing-tricks-for-better-admin-urls/
http://www.slideshare.net/kgoel1/routing-in-drupal-8
http://valuebound.com/resources/blog/drupal-8-how-to-create-the-local-tasks-through-custom-module
https://www.drupal.org/docs/8/api/menu-api/providing-module-defined-actions
Local action links now provided by plugins using YAML discovery and implementing LocalActionInterface
https://www.drupal.org/node/2007444
YAML files for menu links, contextual links, local tasks, and local actions have been renamed
https://www.drupal.org/node/2302893
http://www.wembassy.com/content/module-linksactionyml
http://orangeweb.com.au/drupal-8-local-actions
https://gist.github.com/adityaanurag/1ecfe073d972a4320dea73c4c1dd0c76
https://github.com/drupal8book/token_auth/blob/master/token_auth.links.action.yml
https://drupalapi.alphanodes.com/api/drupal/core!core!modules!block_content!block_content.links.action.yml/8
c: 2016 November 21, Monday, 5:27 PM
Comments
Post new comment