Problem/Motivation
\Drupal\Core\Menu\LocalTaskManagerInterface::getLocalTasks uses 0 and 1 for primary and secondary.
hook_menu_local_tasks_alter discusses placing the altered tasks by level but its not clear in the example (shown below) that the 0 is the level, and not an arbitrary array key.
Steps to reproduce
Review this hook_menu_local_tasks_alter example code and not realise that 0 is signficant.
// Add a tab linking to node/add to all pages.
$data['tabs'][0]['node.add_page'] = [
'#theme' => 'menu_local_task',
'#link' => [
'title' => t('Example tab'),
'url' => Url::fromRoute('node.add_page'),
'localized_options' => [
'attributes' => [
'title' => t('Add content'),
],
],
],
];Contrast that with
// Add a tab linking to node/add to all pages.
$data['tabs'][LocalTaskManagerInterface::LEVEL_PRIMARY]['node.add_page'] = [
'#theme' => 'menu_local_task',
'#link' => [
'title' => t('Example tab'),
'url' => Url::fromRoute('node.add_page'),
'localized_options' => [
'attributes' => [
'title' => t('Add content'),
],
],
],
];Proposed resolution
Replace uses of 0 and 1 in local task manager and hook_menu_local_tasks_alter with constants that signify their importance.
Comments
Comment #2
larowlanComment #3
larowlan