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.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

larowlan created an issue. See original summary.

larowlan’s picture

Issue summary: View changes
larowlan’s picture

Issue summary: View changes

Version: 10.0.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.