Verified Commit a957a4ac authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3425058 by tstoeckler: [regression] Add a fallback in...

Issue #3425058 by tstoeckler: [regression] Add a fallback in DraggableListBuilder::getWeight() to support entities with a NULL weight
parent 4b9ffa3c
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
  }

  /**
+10 −0
Original line number Diff line number Diff line
@@ -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);
  }

}