diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index 285df5a..d1d3581 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -146,8 +146,8 @@ public function id() { * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage, $update = TRUE) { - // Sort elements by weight before saving. - uasort($this->content, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); + ksort($this->content); + ksort($this->hidden); parent::preSave($storage, $update); } diff --git a/core/modules/field_ui/src/Tests/EntityDisplayTest.php b/core/modules/field_ui/src/Tests/EntityDisplayTest.php index 099bc7f..3bcb166 100644 --- a/core/modules/field_ui/src/Tests/EntityDisplayTest.php +++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php @@ -100,6 +100,25 @@ public function testEntityDisplayCRUD() { } /** + * Test sorting of components by name on basic CRUD operations + */ + public function testEntityDisplayCRUDSort() { + $display = entity_create('entity_view_display', array( + 'targetEntityType' => 'entity_test', + 'bundle' => 'entity_test', + 'mode' => 'default', + )); + $display->setComponent('component_3'); + $display->setComponent('component_1'); + $display->setComponent('component_2'); + $display->removeComponent('name'); + $display->save(); + $components = array_keys($display->getComponents()); + $expected = array ( 0 => 'component_1', 1 => 'component_2', 2 => 'component_3',); + $this->assertIdentical($components, $expected); + } + + /** * Tests entity_get_display(). */ public function testEntityGetDisplay() {