diff --git a/core/modules/page/lib/Drupal/page/PageListController.php b/core/modules/page/lib/Drupal/page/PageListController.php index 310bbb4..16d2600 100644 --- a/core/modules/page/lib/Drupal/page/PageListController.php +++ b/core/modules/page/lib/Drupal/page/PageListController.php @@ -24,6 +24,15 @@ public function __construct($entity_type, EntityStorageControllerInterface $stor } /** + * Overrides Drupal\Core\Entity\EntityListController::load(). + */ + public function load() { + $items = $this->storage->load(); + uasort($items, 'page_sort_weight'); + return $items; + } + + /** * Get form for listing page to display for weights. */ public function getForm($form, &$form_state) { diff --git a/core/modules/page/page.module b/core/modules/page/page.module index 695e493..9186058 100644 --- a/core/modules/page/page.module +++ b/core/modules/page/page.module @@ -174,3 +174,15 @@ function page_theme($existing, $type, $theme, $path) { ), ); } + +/** + * Helper to sort objects by weight. + */ +function page_sort_weight($a, $b) { + $a_weight = (is_object($a) && isset($a->weight)) ? $a->weight : 0; + $b_weight = (is_object($b) && isset($b->weight)) ? $b->weight : 0; + if ($a_weight == $b_weight) { + return 0; + } + return ($a_weight < $b_weight) ? -1 : 1; +}