From a957a4acfca32ee650efc35c45d739c30b9ba1e1 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sat, 2 Mar 2024 10:31:10 +0000 Subject: [PATCH] Issue #3425058 by tstoeckler: [regression] Add a fallback in DraggableListBuilder::getWeight() to support entities with a NULL weight --- .../Drupal/Core/Config/Entity/DraggableListBuilder.php | 2 +- .../src/Functional/ConfigDraggableListBuilderTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php index a5b901d50a65..5162aa12192b 100644 --- a/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php +++ b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php @@ -36,7 +36,7 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter */ protected function getWeight(EntityInterface $entity): int|float { /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ - return $entity->get($this->weightKey); + return $entity->get($this->weightKey) ?: 0; } /** diff --git a/core/modules/config/tests/src/Functional/ConfigDraggableListBuilderTest.php b/core/modules/config/tests/src/Functional/ConfigDraggableListBuilderTest.php index 50f1650c9dd5..8688fc517ec9 100644 --- a/core/modules/config/tests/src/Functional/ConfigDraggableListBuilderTest.php +++ b/core/modules/config/tests/src/Functional/ConfigDraggableListBuilderTest.php @@ -59,6 +59,16 @@ public function testDraggableList() { $this->drupalGet('admin/people/roles'); $this->assertSession()->responseContains('<td>' . Html::escape($role_name)); + + // Make sure that NULL weights do not break the list builder. Use the + // configuration API so that the value does not get type-casted according to + // the configuration schema. + \Drupal::configFactory() + ->getEditable('user.role.role_0') + ->set('weight', NULL) + ->save(TRUE); + $this->drupalGet('admin/people/roles'); + $this->assertSession()->statusCodeEquals(200); } } -- GitLab