core/lib/Drupal/Core/Field/FieldItemList.php | 10 +++++++--- core/modules/path/tests/src/Kernel/PathItemTest.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/lib/Drupal/Core/Field/FieldItemList.php b/core/lib/Drupal/Core/Field/FieldItemList.php index 5d13a5e..152005b 100644 --- a/core/lib/Drupal/Core/Field/FieldItemList.php +++ b/core/lib/Drupal/Core/Field/FieldItemList.php @@ -7,6 +7,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\TypedData\DataDefinitionInterface; use Drupal\Core\TypedData\Plugin\DataType\ItemList; /** @@ -378,7 +379,6 @@ protected function defaultValueWidget(FormStateInterface $form_state) { * {@inheritdoc} */ public function equals(FieldItemListInterface $list_to_compare) { - $columns = $this->getFieldDefinition()->getFieldStorageDefinition()->getColumns(); $count1 = count($this); $count2 = count($list_to_compare); if ($count1 === 0 && $count2 === 0) { @@ -396,9 +396,13 @@ public function equals(FieldItemListInterface $list_to_compare) { } // If the values are not equal ensure a consistent order of field item // properties and remove properties which will not be saved. - $callback = function (&$value) use ($columns) { + $property_definitions = $this->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinitions(); + $non_computed_properties = array_filter($property_definitions, function (DataDefinitionInterface $property) { + return !$property->isComputed(); + }); + $callback = function (&$value) use ($non_computed_properties) { if (is_array($value)) { - $value = array_intersect_key($value, $columns); + $value = array_intersect_key($value, $non_computed_properties); ksort($value); } }; diff --git a/core/modules/path/tests/src/Kernel/PathItemTest.php b/core/modules/path/tests/src/Kernel/PathItemTest.php index 88044c3..d7627c3 100644 --- a/core/modules/path/tests/src/Kernel/PathItemTest.php +++ b/core/modules/path/tests/src/Kernel/PathItemTest.php @@ -171,6 +171,24 @@ public function testPathItem() { $this->assertEquals('/foobar', $loaded_node->get('path')->alias); $stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId()); $this->assertEquals('/foobar', $stored_alias); + + // Check that \Drupal\Core\Field\FieldItemList::equals() for the path field + // type. + $node = Node::create([ + 'title' => $this->randomString(), + 'type' => 'foo', + 'path' => ['alias' => '/foo'], + ]); + $second_node = Node::create([ + 'title' => $this->randomString(), + 'type' => 'foo', + 'path' => ['alias' => '/foo'], + ]); + $this->assertTrue($node->get('path')->equals($second_node->get('path'))); + + // Change the alias for the second node to a different one and try again. + $second_node->get('path')->alias = '/foobar'; + $this->assertFalse($node->get('path')->equals($second_node->get('path'))); } }