Problem/Motivation
We want to remove entity uri_callback param that was declared for backward compatible with drupal 7.
Proposed resolution
1) We need to implement Drupal\Core\Entity\EntityInterface::uri() method for every core entity type entity templates already takes precedence over uri_callback
2) We need to drop functions in global namespace (and uri_callback param in entity annotation that reference to this functions).
After this we will remove uses of this param in Entity API.
Remaining tasks
When rendering routes it makes sense to know the route name #2283851: Pass the route name to OutboundRouteProcessorInterface::processOutbound
Open
- Term - #2010132: Canonical taxonomy term link for forum vocabulary is broken
- Comment - #2010202: Deprecate comment_uri()
Done
- Node - #2010162: Convert node_uri() to $node->uri()
- User - #2008616: Convert user_uri() to $user->uri()
- MenuLink - #2010238: Convert menu_link_uri() to $entity->uri()
- ImageStyle - #2010240: Convert image_style_entity_uri() to $entity->uri() Assigned to: kgoel
- Category - #2010244: Convert contact_category_uri() to $entity->uri()
- PictureMapping - #2010216: Convert picture_mapping_uri() to $entity->uri() Assigned to: kgoel
- ConfigTest, ConfigQueryTest - #2010242: Convert config_test_uri() to $entity->uri() Assigned to: kgoel
User interface changes
None.
API changes
Removal of
\Drupal\Core\Entity\EntityTypeInterface::getUriCallback()
\Drupal\Core\Entity\EntityTypeInterface::setUriCallback()
taxonomy_term_uri()
forum_uri()
...complete
This issue is blocked on #1970360: Entities should define URI templates and standard links Assigned to: linclark.
Comments
Comment #1
BerdirSee my comments in the node issue.
This kills the possibility to alter the callback, which in core is used by forum.module for example.
It's a valid argument to say that being able to alter this is wrong, but then we need to find another way to do what e.g. forum does.
One idea that's been floating around is to be able to specify the class used for a specifc bundle, then you could override uri()/label there. That might also make sense as we're moving more business logic into the entity classes, e.g. the pre/postSave methods from the storage controller to the entity classes.
Comment #2
andypost@Berdir yes I get it!
So /core/lib/Drupal/Core/Entity/Entity.php implements base uri() method that checks
bundle and entity for uri callback and have fallback to
entity/type/ID
pathTo remove procedural wrappers we could
Comment #2.0
andypostupdate issues list
Comment #3
andypostrelated issue #1970360: Entities should define URI templates and standard links
Comment #3.0
andypostupdate issue list
Comment #4
xjm#2046289: Deprecate entity uri procedural callbacks (uri_callback) closed as a duplicate of this issue. Salient bits from there:
We can still do most of this, despite forum. In #4 we would deprecate the key instead of removing it.
Comment #5
xjmComment #6
Crell CreditAttribution: Crell commentedClosing #2074497: Convert entities and ->uri() to be route-based and route-aware OR just return a rendered URL from uri() as a dupe. Its description:
Comment #6.0
Crell CreditAttribution: Crell commentedupdate isse list, add blocked issue
Comment #7
andypostLast patch in #2010132-34: Canonical taxonomy term link for forum vocabulary is broken shows nonsense of keeping "uri_callback" as API, so suppose we should drop it here.
Entities handled with URI templates now so conditional fallback to some strange "uri_callback", when template does not exist, is very fragile code so better get rid of it here.
Any alterations should happen only when route is rendered, for that purpose there's a path-processors and it makes sense to make this optimized at the same time.
Thinking about contrib, it makes sense to measure the performance of path aliasing vs route processors (inbound and outbound)
Comment #8
andypostComment #9
BerdirComment #10
xjmComment #11
jhodgdonThis DESPERATELY needs a docs update and a change record. The Entity API docs topic still says you have to put in uri_callback. See new child issue #2667040: Deprecate uri_callback in routes for entities which I am tempted to mark as at least Major but haven't. This was apparently fixed more than 1.5 years ago and there is no change record about it and the docs are still wrong. :(
Comment #12
longwaveI have been looking into this and the related issue in order to alter URIs for specific bundles in contrib, similar to the way forum module tries but currently fails to do this for taxonomy terms.
As I understand it so far, 'uri_callback' is still technically supported but it is basically never going to be used - the only time it is used is when you call Entity::toUrl() with an undefined link relationship (or you ask for the default 'canonical' link but your entity does not define one).
However as the 8.0 ship has sailed and we need to keep BC for anyone using this feature, we can no longer simply remove it as suggested in #2010132: Canonical taxonomy term link for forum vocabulary is broken. The two child bugs are still valid but need fixing in a slightly different way, and the docs indeed are in desperate need of an update.
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commentedI am using OutboundRouteProcessorInterface to point links to proper paths(in my case terms) and EventSubscriberInterface to redirect user to proper path in case he visits the original path directly.
Comment #14
andypostBut we should use entity link templates and deprecate this API in minors
outbound processors is overkill for such cases... let's fix entity level first
Comment #15
longwave@andypost: How can we use different link templates per bundle? I don't see a way of doing this right now. Or are you suggesting adding this as a feature, which would fix this bug more cleanly than adding outbound processors?
Comment #16
xjmThis issue was marked as a beta target for the 8.0.x beta, but is not applicable as an 8.1.x beta target, so untagging.
This could potentially be implemented in a minor with BC, so moving to 8.2.x.
Comment #18
joachim CreditAttribution: joachim commentedHow about adding new type of entity handler for URIs?
The logic in EntityInterface::toUrl() would then be:
- look in the entity type URI templates
- check with each handler
- throw an exception
Comment #21
Alan D. CreditAttribution: Alan D. commentedHas there been a regression from Drupal 7 slip through here in that you can't actually knock out links now?
i.e. silly example, but we've use similar things with conditionals a lot to safely nuke entity links globally on certain conditions without touching the theming layer.
And I couldn't see how this was possible via OutboundRouteProcessor::processOutbound() or OutboundPathProcessor::processOutbound().
Comment #25
gisleRemoving spurious tag - https://www.drupal.org/node/1207020
Comment #31
catchBundle classes have landed, so the forum use case is theoretically covered now.
Comment #35
catchRe-titled #2010202: Deprecate comment_uri(), just needs a re-roll now I think.
#2010132: Canonical taxonomy term link for forum vocabulary is broken forum module is on its way to contrib, that would make this 11.x only, unless we unpostpone that issue so we can complete the deprecation.