User login

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

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Menu%21LocalActionManager.php/function/LocalActio...


Resources:

https://www.drupal.org/docs/8/api/routing-system/introductory-drupal-8-routes-and-controllers-example

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

http://drupal.stackexchange.com/questions/189305/can-we-add-the-destination-query-parameter-to-a-link-from-yml-c...

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

Searched words: 
drupal 8 add action link drupal 8 add add content link drupal 8 local task add Drupal 8 see route providing path drupal 8 node id as route parameter yaml what are the route names for node add in Drupal 8 Drupal 8 see route providing path

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.