diff --git a/core/lib/Drupal/Core/Entity/EntityListBuilder.php b/core/lib/Drupal/Core/Entity/EntityListBuilder.php index a9c649888df142751fb3a8a5556ef98d88fc7ac2..1eb4fc78caf79c824fa2883b1b04fa69a7227ef3 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 aa85d4db709c63a777b1a2277ffd97b33d9cbe0b..2d6c286fd5d798d005b95d215889c596416c2e9c 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}