By berdir on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.4.x
Introduced in version:
8.4.0
Issue links:
Description:
The Path field is special and does not store its data in a field table like other fields. Before 8.4.x, it was only able to write data and was used to enable the Path widget.
Starting with 8.4.x, accessing the current value on a path field will automatically load it from the url_alias table.
8.3.x
$node = Node::load(1);
$alias_storage = \Drupal::service('path.alias_storage');
// Contains the existing alias.
$stored_alias = $alias_storage->lookupPathAlias('/node/1', 'en');
// This is empty.
$alias_from_node = $node->path->alias;
8.4.x
$node = Node::load(1);
$alias_storage = \Drupal::service('path.alias_storage');
// Contains the existing alias.
$stored_alias = $alias_storage->lookupPathAlias('/node/1', 'en');
// This contains the alias now.
$alias_from_node = $node->path->alias;
$alias_from_node == $stored_alias;
This also impacts REST, JSON API and GraphQL (i.e. the API-First Initiative) and other features (such as Default Content) that rely on serialized entities, which will now automatically include the aliases.
Impacts:
Site builders, administrators, editors
Module developers