This change record has been updated based on https://www.drupal.org/node/2302893.
As a part of the new New Symfony-based routing system, the action link definitions are moving out of hook_menu() and into plugins implementing \Drupal\Core\Menu\LocalActionInterface. The primary discovery mechanism is YAML files following the naming pattern
A default implementation \Drupal\Core\Menu\LocalActionDefault is used unless another class is specified in the YAML file.
Drupal 7
function contact_menu() {
$items['admin/structure/contact'] = array(
'title' => 'Contact form',
'description' => 'Create a system contact form and set up categories for the form to use.',
'page callback' => 'contact_category_list',
'access arguments' => array('administer contact forms'),
'file' => 'contact.admin.inc',
);
$items['admin/structure/contact/add'] = array(
'title' => 'Add category',
'page callback' => 'drupal_get_form',
'page arguments' => array('contact_category_edit_form'),
'access arguments' => array('administer contact forms'),
'type' => MENU_LOCAL_ACTION,
'weight' => 1,
'file' => 'contact.admin.inc',
);
}
Drupal 8
Local actions are defined in a YAML format, named after the module they are defined by ($modulename.links.action.yml). See Providing module-defined actions.
Yaml File
contact_category_add_action:
route_name: contact_category_add
title: 'Add category'
appears_on:
- contact_category_list
Each local action is represented by a plugin with a definition from the YAML. Each local action definition contains four keys:
id: The machine name of the plugin
route_name: The machine name of the local action route.
title: The title of the local action. Will be passed on to t().
title_context: Optional context to pass on with the title to t().
appears_on: An array of route names for this action to be display on.
In order for a local action to be converted, both it and the path it appears on must first be converted to routes.
See #1971384: [META] Convert page callbacks to controllers for the list of issues and the WSCCI Conversion guide for instructions.
Note that the MENU_LOCAL_ACTION type did more than just present it as a local action, it also manipulated the breadcrumb trail and controlled which tabs appeared on its page. In order to preserve that behavior, a new constant was introduced, MENU_SIBLING_LOCAL_TASK.
Comments
URL parameters?
Im wondering how to create links with parameters for example action link to "/admin/node/somebundle". Is it possible to set parameter node_type for this link?
create_article:
route_name: node.add
title: 'Create new article'
appears_on:
- somewhere
You can use route_parameters
You can use route_parameters option, for example blog_post node type for node.add route:
Don't works
I´ve tried to implement the route_parameters but it is not working the link tasks is still displayed on others node types. Can you please confirm this?
See Blog module
Yes, it works for me. I installed blog module:
https://www.drupal.org/project/blog
Link task is displayed on /blog page to create a blog node.
Works to pass parameters in module.action.yml
in mymodule.links.action.yml
And remember to 'drupal cr'
it really Helps to use drupal console
drupal router:debug
or in my case drupal router:debug entity.webform.canonical
thank you @enzo !