Drupal 8 Local Actions

By Anton Baggerman, Freelance Drupal Developer.

Local actions can be defined for operations related to a given route. For example, adding content is a common operation for the content management page, so it should be a local action. In Drupal 8 local actions are defined in .links.action.yml files, similar to local tasks. These files need to be part of a custom module.

This example creates an additional local action "Import View" on the Views page (see image). Those familiar with Drupal 7 may ask "but isn't that already there in Views?" and the answer is no. Config Entities in Drupal 8 now take care of all configuration imports and exports so it has been removed from Views.

Our new local action is simply a shortcut to /admin/config/development/configuration/single/import and we add it to the existing Views route. Because of this we only need two files, the standard .info file for our module and a .links.action.yml file. We are not providing any additional functionality so we do not need a .module file, and we are not defining a new route so we don't need a .routing.yml file either.

Module info file - example3.info.yml

name: Example Local Action
type: module
description: 'Drupal 8 Local Action Example.'
package: custom
version: 1.0
core: 8.x

Local action definitions - example3.links.action.yml

# yaml file to define one or more local action(s).
# Definitions can contain any of the following:
# title: (required) The untranslated title of the menu link.
# description: The untranslated description of the link.
# route_name: (optional) The route name to be used to build the path. Either a
#   route_name or a link_path must be provided.
# route_parameters: (optional) The route parameters to build the path. An array.
# link_path: (optional) If you have an external link use link_path instead of
#   providing a route_name.
# weight: (optional) An integer that determines the relative position of local
#   action items; higher-weighted items sink. Defaults to 0.
#   Local action items with the same weight are ordered alphabetically.
# appears_on: One or more routes that this local action should appear on.
  route_name: config.import_single
  title: 'Import View'
  weight: 1
    - views_ui.list

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Fill in the blank.