Problem/Motivation

hook_menu_local_tasks_alter is passed a third argument in \Drupal\Core\Menu\LocalTaskManager::getLocalTasks, which is currently undocumented in menu.api.php.

The hook invocation looks like (truncated):

  /**
   * {@inheritdoc}
   */
  public function getLocalTasks($route_name, $level = 0) {
    if (!isset($this->taskData[$route_name])) {
      $cacheability = new CacheableMetadata();
      $cacheability->addCacheContexts(['route']);
[...]
        $this->moduleHandler->alter('menu_local_tasks', $this->taskData[$route_name], $route_name, $cacheability);
        $this->taskData[$route_name]['cacheability'] = $cacheability;
[...]
  }

And the hook documentation shows an example as:

function hook_menu_local_tasks_alter(&$data, $route_name) {

There's a lot of value in adding cache tags and dependencies to $cacheability in a hook, so we should document it.

Proposed resolution

Document the third argument.

Remaining tasks

Review the patch.

User interface changes

None.

API changes

The API documentation for hook_menu_local_tasks_alter will change.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

samuel.mortenson created an issue. See original summary.

samuel.mortenson’s picture

Status: Active » Needs review
FileSize
1.07 KB

Here's a patch.

borisson_’s picture

This is both a documentation improvement and an actual code change, but I see nothing in the summary about that code change. Should we split this up or document why we're doing that?

samuel.mortenson’s picture

@borisson_ The code change is just in the API example - not in code that actually runs in core.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

I can't believe I missed that, in that case, this looks very good.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

@samuel.mortenson nice find.

Committed and pushed 3f70e70132 to 8.6.x and f05d04d068 to 8.5.x. Thanks!

  • alexpott committed 3f70e70 on 8.6.x
    Issue #2945184 by samuel.mortenson: Third argument passed to...

  • alexpott committed f05d04d on 8.5.x
    Issue #2945184 by samuel.mortenson: Third argument passed to...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.