diff --git a/core/modules/path/path.module b/core/modules/path/path.module index 97b9e27..dbf752b 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -83,8 +83,8 @@ function path_entity_base_field_info(EntityTypeInterface $entity_type) { function path_entity_translation_create(ContentEntityInterface $translation) { foreach ($translation->getFieldDefinitions() as $field_name => $field_definition) { if ($field_definition->getType() === 'path' && $translation->get($field_name)->pid) { - // If there are values and a PID, update the langcode and unset the pid - // to save this as a new alias. + // If there are values and a path ID, update the langcode and unset the + // path ID to save this as a new alias. $translation->get($field_name)->langcode = $translation->language()->getId(); $translation->get($field_name)->pid = NULL; } diff --git a/core/modules/path/tests/src/Kernel/PathItemTest.php b/core/modules/path/tests/src/Kernel/PathItemTest.php index 769fa3a..b73d8c2 100644 --- a/core/modules/path/tests/src/Kernel/PathItemTest.php +++ b/core/modules/path/tests/src/Kernel/PathItemTest.php @@ -11,6 +11,7 @@ * Tests loading and storing data using PathItem. * * @group path + * @group failing */ class PathItemTest extends KernelTestBase { @@ -85,7 +86,7 @@ public function testPathItem() { $translation->get('path')->alias = '/furchtbar'; $translation->save(); - // Assert the alias on the English node, the German translation and the + // Assert the alias on the English node, the German translation, and the // stored aliases. $node_storage->resetCache(); $loaded_node = $node_storage->load($node->id()); @@ -125,7 +126,7 @@ public function testPathItem() { $old_alias = $alias_storage->lookupPathSource('/foo', $node->language()->getId()); $this->assertFalse($old_alias); - // Reload the node to make sure that it is possibly to set a value + // Reload the node to make sure that it is possible to set a value // immediately after loading. $node_storage->resetCache(); $loaded_node = $node_storage->load($node->id()); @@ -149,6 +150,25 @@ public function testPathItem() { $stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId()); $this->assertFalse($stored_alias); + + // Check that reading, updating and reading the computed alias again in the + // same request works without clearing any caches in between. + $loaded_node = $node_storage->load($node->id()); + $loaded_node->get('path')->alias = '/foo'; + $loaded_node->save(); + + $this->assertFalse($loaded_node->get('path')->isEmpty()); + $this->assertEquals('/foo', $loaded_node->get('path')->alias); + $stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId()); + $this->assertEquals('/foo', $stored_alias); + + $loaded_node->get('path')->alias = '/foobar'; + $loaded_node->save(); + + $this->assertFalse($loaded_node->get('path')->isEmpty()); + $this->assertEquals('/foobar', $loaded_node->get('path')->alias); + $stored_alias = $alias_storage->lookupPathAlias('/' . $node->toUrl()->getInternalPath(), $node->language()->getId()); + $this->assertEquals('/foobar', $stored_alias); } }