Change record status: 
Project: 
Introduced in branch: 
8.2.x
Introduced in version: 
8.2.0
Description: 

From 8.2.0 entities can now optionally be linked to by their UUID.

E.g given a node with ID 21 and UUID 68d0a104-a5bf-466c-a429-f871d91f9580 the following two URLs are equivalent:

node/21
node/68d0a104-a5bf-466c-a429-f871d91f9580

To check if an entity supports linking by UUID you can use the uuid link template.

if ($entity->hasLinkTemplate('uuid')) {
  $url = $entity->toUrl('uuid');
}

Core includes support for taxonomy terms, nodes and users by default.

To add UUID linking support to your entity you need to do the following:
- add a new route that uses the UUID pattern - either using an Entity route provider or from a routing.yml file. See Drupal\node\Entity\NodeRouteProvider or taxonomy.routing.yml for examples.
- add a new link template to your entity's annotation - see \Drupal\taxonomy\Entity\Term for an example:

/**
 * @ContentEntityType(
 *   ...
 *   links = {
 *     uuid = "/node/{node}",
 *   }
 * )
*/
Impacts: 
Site builders, administrators, editors
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

friera’s picture

Can you please provide an example to do it?