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

Done

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

Berdir’s picture

See 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.

andypost’s picture

Issue tags: -Novice

@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 path

To remove procedural wrappers we could

$uri = parent::uri();
if ($uri['path'] == "entity/$bundle/$ID") {
  $uri['path'] = "node/$ID";
}
andypost’s picture

Issue summary: View changes

update issues list

andypost’s picture

andypost’s picture

Issue summary: View changes

update issue list

xjm’s picture

#2046289: Deprecate entity uri procedural callbacks (uri_callback) closed as a duplicate of this issue. Salient bits from there:

  • As @berdir and @larowlan have pointed out, we can't rip out support for the per-bundle URIs because of forum.
  • Related issue: #2047283: Improve documentation for EntityType::$links
  • My original suggestion:
    [04:20am] claudiu_cristea: alexpott: xjm: (1) make url() use canonical (2) add links.canonical to all entities (3) deprecate procedural (4) remove url_callback key
    [04:21am] xjm: (5) change notify it

    We can still do most of this, despite forum. In #4 we would deprecate the key instead of removing it.

  • From @claudiu.cristea:
    1. Bundle-based URIs are no more supported for content entities, starting from #1970360: Entities should define URI templates and standard links.
    2. Method url() was implemented to use link templates in EntityNG. So, all entities that are extending EntityNG and are defining link patterns are already using them. For those entities we can safely remove the url_callback annotation and drop the old procedural callback. Proposal: Remove uri_callback annotation and related procedural callbacks.
    3. There are no EntityNG based entities that are not defining link templates. A new hypothetical EntityNG not defining links will fallback to old uri_callback mechanism when calling ->uri() without parameters because of
      // For a canonical link (that is, a link to self), look up the stack for
      // default logic. Other relationship types are not supported by parent
      // classes.
      if ($rel == 'canonical') {
        return parent::uri();
      }
      

      That is looking up to parent Entity method that is still using uri_callback. Proposal: Break here the call to the legacy mechanism by replacing with:

      if ($rel == 'canonical') {
        return 'entity/' . $this->entityType . '/' . $this->id();
      }
      
    4. Configurables, that are based (via ConfigEntityBase) on Entity, are not inheriting the EntityNG new ->uri() method and are still using the procedural callback. Adopt one of next proposals:
      1. Add a ->uri() (that is using link templates) method to ConfigEntityBase and link templates in configurable annotations.
      2. Change the Entity::url() method to use new template links and annotate link templates in configurables.
xjm’s picture

Crell’s picture

Closing #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:

Currently the entity annotations are re-defining the route path patterns and have a uri() method that doesn't actually return a viable link.

The entity links should be aware of the routes (or even generate the routes form them) and as with all link rendering, we should be using hte route and parameters, not a path to check access and generate the link.

Crell’s picture

Issue summary: View changes

update isse list, add blocked issue

andypost’s picture

Issue summary: View changes

Last 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)

andypost’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update +API clean-up, +API cleanup, +Needs change notification, +beta target
Berdir’s picture

Issue summary: View changes
xjm’s picture

Issue tags: -Needs change notification +Needs change record
jhodgdon’s picture

This 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. :(

longwave’s picture

I 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.

Anonymous’s picture

I 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.

andypost’s picture

But 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

longwave’s picture

@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?

xjm’s picture

Version: 8.0.x-dev » 8.2.x-dev
Issue tags: -beta target

This 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.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joachim’s picture

How 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

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Alan D.’s picture

Has 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.

function hook_entity_info_alter(&$entity_info) {
  $entity_info['node']['uri callback'] = 'no_url';
}

function no_url($node) {
  return array(
    'path' => NULL,
  );
}

And I couldn't see how this was possible via OutboundRouteProcessor::processOutbound() or OutboundPathProcessor::processOutbound().

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gisle’s picture

Issue tags: -API cleanup

Removing spurious tag - https://www.drupal.org/node/1207020

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Bundle classes have landed, so the forum use case is theoretically covered now.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Re-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.