Open klonos opened 3 years ago
Related: https://www.drupal.org/project/drupal/issues/2720215
How do i discover the canonical route for an entity type?
I do not have a
ContentEntity
instance, only an instanceEntityTypeInterface
. How do I discover the canonical Route for the entity type?
getCanonicalRoute()
seems like a good contender, but for some reason it's protected and not implemented byNodeRouteProvider
orUserRouteProvider
The inspiration for this request is this issue for the devel module: https://github.com/backdrop-contrib/devel/issues/115. The fix for that issue is simple, but:
If all core entities defined a canonical URI, then instead of requiring to manually account for any new core entity type or any custom one, Devel would be able to be more "dynamic", and do something like this:
$entity_types = entity_get_info();
foreach ($entity_types as $entity_type) {
$canonical_link = $entity_type->get_links('canonical');
[... add devel-provided links ...]
}
...or take advantage of a hook, and add these to every entity type:
links = {
"devel" = "/node/{node}/devel",
"devel-load" = "/node/{node}/devel/load",
"devel-render" = "/node/{node}/devel/render",
}
At the very minimum, we should add canonical URIs to all core-provided entity types.
This is basically a request to add the same feature as https://www.drupal.org/project/drupal/issues/1970360
D8 change record: https://www.drupal.org/node/2020491