From eead942e3b4643bd291786b707b4826586aa43d3 Mon Sep 17 00:00:00 2001
From: catch <6915-catch@users.noreply.drupalcode.org>
Date: Wed, 10 Jul 2024 10:19:42 +0100
Subject: [PATCH] Issue #3410091 by mglaman, alexpott, smustgrave, bnjmnm,
 quietone: [regression] Menu List Builder  getEntityIds() no longer calls
 getEntityListQuery

(cherry picked from commit c257de99e360515cb892a3c67596cb019ecfe19f)
---
 core/lib/Drupal/Core/Entity/EntityListBuilder.php | 10 +++++++++-
 core/modules/menu_ui/src/MenuListBuilder.php      | 13 +------------
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/core/lib/Drupal/Core/Entity/EntityListBuilder.php b/core/lib/Drupal/Core/Entity/EntityListBuilder.php
index a9c649888df1..1eb4fc78caf7 100644
--- a/core/lib/Drupal/Core/Entity/EntityListBuilder.php
+++ b/core/lib/Drupal/Core/Entity/EntityListBuilder.php
@@ -50,6 +50,14 @@ class EntityListBuilder extends EntityHandlerBase implements EntityListBuilderIn
    */
   protected $limit = 50;
 
+  /**
+   * The entity key to sort the list by.
+   *
+   * This can be overridden in child classes to sort the list by a different
+   * entity key.
+   */
+  protected const SORT_KEY = 'id';
+
   /**
    * {@inheritdoc}
    */
@@ -108,7 +116,7 @@ protected function getEntityIds() {
   protected function getEntityListQuery(): QueryInterface {
     $query = $this->getStorage()->getQuery()
       ->accessCheck(TRUE)
-      ->sort($this->entityType->getKey('id'));
+      ->sort($this->entityType->getKey(static::SORT_KEY));
 
     // Only add the pager if a limit is specified.
     if ($this->limit) {
diff --git a/core/modules/menu_ui/src/MenuListBuilder.php b/core/modules/menu_ui/src/MenuListBuilder.php
index aa85d4db709c..2d6c286fd5d7 100644
--- a/core/modules/menu_ui/src/MenuListBuilder.php
+++ b/core/modules/menu_ui/src/MenuListBuilder.php
@@ -17,18 +17,7 @@ class MenuListBuilder extends ConfigEntityListBuilder {
   /**
    * {@inheritdoc}
    */
-  protected function getEntityIds() {
-    $query = $this
-      ->getStorage()
-      ->getQuery()
-      ->sort('label', 'ASC');
-
-    // Only add the pager if a limit is specified.
-    if ($this->limit) {
-      $query->pager($this->limit);
-    }
-    return $query->execute();
-  }
+  protected const SORT_KEY = 'label';
 
   /**
    * {@inheritdoc}
-- 
GitLab