Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#2 | 2945184-2.patch | 1.07 KB | samuel.mortenson |
Comments
Comment #2
samuel.mortensonHere's a patch.
Comment #3
borisson_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?
Comment #4
samuel.mortenson@borisson_ The code change is just in the API example - not in code that actually runs in core.
Comment #5
borisson_I can't believe I missed that, in that case, this looks very good.
Comment #6
alexpott@samuel.mortenson nice find.
Committed and pushed 3f70e70132 to 8.6.x and f05d04d068 to 8.5.x. Thanks!