We have these two functions, menu_list_system_menus() and menu_ui_get_menus(), which just sorta return lists of the menus (i.e., menu entities) known to the system. These were needed in D7, since menus weren't config, and we used to call them a lot more. Now that menus are just config entities, we can replace these functions with standard entity system calls.

Proposed Resolution

Deprecate both functions for removal in D10.

Remaining Tasks

Commit the merge request.

API changes

Two old functions will be deprecated.

UI changes

None.

Data model changes

None.

Issue fork drupal-1882552

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sun’s picture

andypost’s picture

andypost’s picture

yesct’s picture

andypost’s picture

Suppose this logic could be moved to MenuAccessController after #2012916: Implement access controller for the menu and menu link entity

tim.plunkett’s picture

#2084197: Uninstalling menu module removes all custom menus doesn't remove this, but does relegate it to only be used when we actually care that these are from system (system_preprocess_block, menu_set_active_menu_names, etc)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Version: 8.6.x-dev » 8.7.x-dev
Issue summary: View changes
Issue tags: +Kill includes
voleger’s picture

andypost’s picture

Status: Active » Needs review
Issue tags: +Needs change record
StatusFileSize
new3.95 KB

It needs CR when there's agreement on final place

I think it could be placed to Menu entity

After replacing usage I think WizardPluginBase needs follow-up to get rid of condition (dependency on muni_ui module) because Menu entity defined in system module

Also http://grep.xnddx.ru/search?text=menu_ui_get_menus widely used in contrib and probably needs another follow-up

voleger’s picture

andypost’s picture

+++ b/core/modules/system/src/Entity/Menu.php
@@ -118,4 +119,20 @@ public function delete() {
+   * Returns an array containing the names of system-defined (default) menus.
...
+  public static function getSystemMenus() {
+    return [
+      'tools' => new TranslatableMarkup('Tools'),
+      'admin' => new TranslatableMarkup('Administration'),
+      'account' => new TranslatableMarkup('User account menu'),
+      'main' => new TranslatableMarkup('Main navigation'),
+      'footer' => new TranslatableMarkup('Footer menu'),
+    ];

I still not sure that it needed at all.
Contrib mostly using menu_ui_get_menus() and not many places, so probably better to inline this array there

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/modules/menu_ui/menu_ui.module
@@ -440,7 +440,7 @@ function menu_ui_form_node_type_form_builder($entity_type, NodeTypeInterface $ty
 function menu_ui_get_menus($all = TRUE) {

We never call this with something other than TRUE. We should deprecate that. And remove the menu_list_system_menus() completely. It's not necessary for core. Before doing this we should have a look in contrib to see how it is used.

In fact thinking about this some more perhaps we can remove this too and replace with Menu::loadMultiple() and tell people to sort it themselves. The asort() doesn't look that useful here anyway.

The only usage with FALSE I have in my contrib is devel but the could be replaced by a Menu::loadMultiple().

dawehner’s picture

I talked with @alexpott about this specific issue and we came up with a 3 step plam:

  1. Inline menu_list_system_menus() into menu_ui_get_menus() and deprecated it: This issue
  2. Get rid of the usage of menu_ui_get_menus() in #3021804: Remove optional dependency on menu_ui module in \Drupal\views\Plugin\views\wizard\WizardPluginBase as its not needed
  3. Get rid of menu_ui_get_menus as its kind of broken: #3028612: Deprecate menu_ui_get_menus() and replace all of its usages
alexpott’s picture

andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record +Needs change record updates
StatusFileSize
new3.07 KB

Looks it blocked on #3021804: Remove optional dependency on menu_ui module in \Drupal\views\Plugin\views\wizard\WizardPluginBase

Also CR should tell that this function should not be used and require sorting of menus

Status: Needs review » Needs work

The last submitted patch, 23: 1882552-23.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

StatusFileSize
new1.11 KB
new3.06 KB

reroll & fix

andypost’s picture

StatusFileSize
new2.83 KB

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

voleger’s picture

Version: 8.9.x-dev » 9.1.x-dev
StatusFileSize
new2.84 KB

Rerolled against 9.0.x

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new2.1 KB
new3.84 KB

Re-roll for 9.3 and added deprecation test

andypost’s picture

andypost’s picture

Status: Needs review » Needs work

The last submitted patch, 32: 1882552-32.patch, failed testing. View results

daffie’s picture

Issue tags: +Needs reroll
andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new571 bytes
new2.56 KB
longwave’s picture

Status: Needs review » Reviewed & tested by the community

This is simple now the Views wizard issue is resolved.

voleger’s picture

Yes, it is the easy one and is ready. +1 for RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/menu_ui/menu_ui.module
@@ -433,7 +433,8 @@ function menu_ui_form_node_type_form_builder($entity_type, NodeTypeInterface $ty
 function menu_ui_get_menus($all = TRUE) {
   if ($custom_menus = Menu::loadMultiple()) {
     if (!$all) {
-      $custom_menus = array_diff_key($custom_menus, menu_list_system_menus());
+      $menus = ['tools', 'admin', 'account', 'main', 'footer'];
+      $custom_menus = array_diff_key($custom_menus, array_combine($menus, $menus));
     }
     foreach ($custom_menus as $menu_name => $menu) {
       $custom_menus[$menu_name] = $menu->label();

I think we can re-write this in a better way that we will result in less throwing away of objects... by using an entity query:

  if (!$all) {
    $menus_to_load = \Drupal::entityTypeManager()->getStorage('menu')->getQuery()->condition('id', ['tools', 'admin', 'account', 'main', 'footer'], 'NOT IN')->execute();
  }
  if ($custom_menus = Menu::loadMultiple($menus_to_load ?? NULL)) {
    foreach ($custom_menus as $menu_name => $menu) {
      $custom_menus[$menu_name] = $menu->label();
    }
    asort($custom_menus);
  }
  return $custom_menus;
voleger’s picture

Assigned: Unassigned » voleger
voleger’s picture

Assigned: voleger » Unassigned

voleger’s picture

Status: Needs work » Needs review

Addressed #40

phenaproxima’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Couple of nitpicks, and one thing that I think may be incorrect and needing explicit test coverage. Sorry!

Also, can we update the issue summary? Its proposed resolution seems to be pretty far out of date, as far as I can tell...

tedbow made their first commit to this issue’s fork.

alexpott’s picture

FWIW there is another option here I like. We never call menu_ui_get_menus(FALSE) so we could and probably should deprecate the $all argument and therefore we don't need to make any changes to menu_ui_get_menus() other than to add the @trigger_error()!

alexpott’s picture

A big advantage to #47 is that in Drupal 10 we won't be hardcoding menu IDs anywhere.

alexpott’s picture

The only use of menu_ui_get_menus(FALSE) in contrib looks like devel - see http://codcontrib.hank.vps-private.net/search?text=menu_ui_get_menus - imo that's not enough to keep it.

The one construction that is interesting is:

  $menu_enabled = $this->moduleHandler->moduleExists('menu_ui');
  $menus = $menu_enabled ? menu_ui_get_menus() : menu_list_system_menus();

This code is flawed because it assumes the menu config is only around when menu_ui is enabled. So that points to the possibility of completely deprecating menu_ui_get_menus() too - and suggesting people do:

$menus =  array_map(function ($menu) { return $menu->label(); },  \Drupal\system\Entity\Menu::loadMultiple());

instead.

andypost’s picture

@alexpott that's exactly what I did in related issue

The usage is https://git.drupalcode.org/project/devel/-/blob/4.x/devel_generate/src/P...

tedbow’s picture

Status: Needs work » Needs review

re #49 @alexpott I think that seems like a good idea. Done

phenaproxima’s picture

I've updated the change record to reflect the fact that these functions are deprecated in Drupal 9.3.0. Otherwise, I think it is accurate as best I can tell. Removing the tag.

phenaproxima’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Rewrote the IS to reflect what we're actually up to.

alexpott’s picture

Marked #3028612: Deprecate menu_ui_get_menus() and replace all of its usages as a duplicate of this one since this one is now deprecating menu_ui_get_menus() too.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @phenaproxima! This ended up being very straightforward, thanks @alexpott for the clean suggestion

phenaproxima’s picture

Title: Get rid of menu_list_system_menus() » Get rid of menu_list_system_menus() and menu_ui_get_menus()
alexpott’s picture

Title: Get rid of menu_list_system_menus() and menu_ui_get_menus() » Deprecate menu_list_system_menus() and menu_ui_get_menus()
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Still need to fix menu_ui_form_node_type_form_alter() to not use menu_ui_get_menus() - see #3028612: Deprecate menu_ui_get_menus() and replace all of its usages for how.

phenaproxima’s picture

Status: Needs work » Needs review
andypost’s picture

Status: Needs review » Needs work
andypost’s picture

Status: Needs work » Needs review

Fixed code-style and added asort() as old code doing - it means a lack of test for sorting for menus (probably needs follow-up)

PS: unpublished patches as MR used now

tedbow’s picture

@andypost got catch on the asort()!

re

it means a lack of test for sorting for menus (probably needs follow-up)

Did we actually have test for this before? I don't see an existing test for menu_ui_get_menus()?

Since we are deprecating menu_ui_get_menus() and we just have suggested code in the change record for how to replace it I don't think we need test coverage for that in particular.

But maybe we need to add a follow-up to assert the menu in the Node Type form so then the asort() could not be accidently removed in menu_ui_form_node_type_form_alter()

I couldn't find any test that covers menu_ui_form_node_type_form_alter() now but I could be wrong.

tedbow’s picture

Status: Needs review » Reviewed & tested by the community

Added the follow up #3221493: Add test coverage for menu order in node type form

I think this looks good now!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7bc0a6d and pushed to 9.3.x. Thanks!

  • alexpott committed 7bc0a6d on 9.3.x
    Issue #1882552 by andypost, phenaproxima, voleger, tedbow, alexpott, tim...
andypost’s picture

Status: Fixed » Closed (fixed)

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