Change record status: 
Project: 
Introduced in branch: 
11.2.x
Description: 

In some cases, it is necessary to change the links depending on the current request, or the granularity of LocalActionManager::getActionsForRoute is not sufficient (for example local tasks depending on the entity bundle).

For this case, a new hook_local_actions_render_alter() has been added.
Example:

function hook_local_actions_render_alter(&$data, $route_appears) {
  // Add an additional local action for a certain route.
  if ($route_appears == 'my.route') {
    $data['node.add_article'] = [
      '#theme' => 'menu_local_action',
      '#link' => [
        'title' => t('Add article'),
        'url' => Url::fromRoute('node.add', ['node_type' => 'article']),
      ],
    ];
  }
}

To keep the consistency, the existing hook_menu_local_tasks_alter() hook was renamed from hook_menu_local_tasks_alter() to hook_local_tasks_render_alter().

hook_menu_local_tasks_alter() hook is deprecated in 9.3.0 and will be removed from 10.0.0. Existing implementations should make the following changes:

Before:

function my_module_menu_local_tasks_alter(&$data, $route_name, \Drupal\Core\Cache\RefinableCacheableDependencyInterface &$cacheability) {
  // Hook implementation.
}

After:

function my_module_local_tasks_render_alter(&$data, $route_name, \Drupal\Core\Cache\RefinableCacheableDependencyInterface &$cacheability) {
  // Hook implementation.
}
Impacts: 
Module developers