API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
The documentation on this page related to routing appears to have some errors in it. I can tell you that it's wrong, but I'm not quite sure what it should be yet. If someone can help me figure out what it should say I'm happy to update things.
Right now, the documentation says this:
For content entities that are displayed on their own pages, the annotation will refer to a 'uri_callback' function, which takes an object of the entity interface you have defined as its parameter, and returns routing information for the entity page; see node_uri() for an example. You will also need to add a corresponding route to your module's routing.yml file; see the entity.node.canonical route in node.routing.yml for an example, and see Entity routes below for some notes.
Optionally, instead of defining routes, routes can be auto generated by providing a route handler. See Entity routes. Otherwise, define routes and links for the various URLs associated with the entity. These go into the 'links' annotation, with the link type as the key, and the path of this link template as the value. The corresponding route requires the following route name: "entity.$entity_type_id.$link_template_type". See Entity routes below for some routing notes. Typical link types are:The node.routing.yml does not have an entry for the entity.node.canonical route, and the annotation for \Drupal\node\Entity\Node does not have a "uri_callback" key. I believe this is related to #2010184: [meta] convert ‘uri_callback’ entities param to EntityInterface::uri() method. The entity.node.canonical route is not dynamically generated, as are most other similar styles routes. It does look forum, and comment entities have not been updated to the new pattern yet.
The newer, and from what I can tell recommended, pattern is the 2nd one described in the documentation above. Providing a route handler.
Is the use of "uri_callback" in an annotation deprecated? Is it removed and we're just figuring out how to deal with comment/forum entities still? We should either remove that block, or update it so that it references a module like comment that actually makes use of the system being described.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | interdiff-2667040.txt | 2.01 KB | longwave |
| #17 | 2667040-uri_callback-docs.patch | 5.45 KB | longwave |
Issue fork drupal-2667040
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 2667040-deprecate-uricallback
changes, plain diff MR !14282
Comments
Comment #2
jhodgdonUm.
OK, so the second paragraph does say that you have the option of providing the routes in a routing.yml file, or using a route handler class. That is correct -- you can do either one. Node, and I think all the rest of the core entities, use route handlers.... so I think the 2nd paragraph is fine.
So... it looks like just the first paragraph is wrong. You don't have to use uri_callback any more, and in fact it seems to be kind of deprecated.
It looks like it was removed as part of #2010184: [meta] convert ‘uri_callback’ entities param to EntityInterface::uri() method or a related issue, but the docs were unfortunately not updated and there is also not a change notice. :(((((
I think we should make this a child issue of that other one. I'll comment over there too. Not having a change record and having docs like this is Not Really OK.
Comment #3
longwaveAn attempt at improving this. It does appear that uri_callback is effectively deprecated now, though it is still used in some edge cases.
Comment #4
jhodgdonThanks! Most of this seems like a great improvement.
One thing I found confusing though:
What does this really mean, about using the uri callback for the bundle? I don't understand it. Actually, I don't understand the previous docs either, but the added text 'and the one for the entity type would normally be used' makes it even more confusing, in my opinion.
Comment #5
longwaveLet's try a simpler approach to that section.
Comment #6
jhodgdonAh, that is definitely way more clear!!
Nitpick: maybe replace "the" with "this" at the end? "... for this bundle only".
Comment #7
longwaveYep, that reads better.
Comment #8
jhodgdonOK, looks good to me, thanks!
Comment #10
longwaveRandom fail in Drupal\views_ui\Tests\OverrideDisplaysTest, back to RTBC
Comment #11
berdirThanks for working on this.
I think we should officially deprecate uri_callback and this documentation should clarify that a) it is deprecated and b) it only works when *not* using link templates. I even wondered if we should go as far as removing any documentation about it. The only reason to not remove the code right now is because that would be an API change and we have in fact one working implementation of it in core. So we could even argue that we shouldn't document a feature that you're not supposed to use.
As mentioned in other issues, the definition on the term entity is bogus, it's not used because it has link templates. The only case where it is in fact used is aggregator items. And there it's IMHO bad usage because it's really the URL to the external source, *not* the entity in Drupal. We should have just added a getSourceUrl() or so method. Similar for the file entity, which does an even weirder thing by overwriting the url() method (which nobody thought to update when toUrl() was added).
Comment #12
jhodgdonDeprecating it seems like a good idea. In which case this is not just a Documentation issue any more.
Comment #13
longwaveAdded deprecation warnings to the interface and member variable, and reworded the existing uses to make the warning even stronger.
Comment #14
berdirI doubt this will get into 8.0.x, so we should probably say deprecated in 8.1.x
Comment #15
jhodgdonOr more likely, 8.2.
Comment #16
jhodgdonAlso I think most of our deprecation messages say something like:
@deprecated in 8.1.0...
not
... in Drupal 8.0.x-dev ...
Really though... I don't think that saying to use toUrl() for URL generation is all that relevant here. The $uri_callback() was more of a substitute for links annotation, from a developer perspective (the developer who is creating the entity).
So ... how about also saying to define the URLs for entities using the links annotation or a route handler, and maybe linking to the entity API topic for more information?
Whenever you have a class with namespace in docs, start it with \
Comment #17
longwaveI cheated by basically copying the deprecation notice from label_callback, hopefully improved in this version.
Comment #30
longwaveThis came up as a random triage bug in #bugsmash.
I think is more of a task than a bug if it is just something we want to deprecate, however we can only deprecate critical things in 9.5.x for removal in 10.0.x, so postponing until 10.1.x now.
Comment #31
quietone commentedNo longer postponed
Comment #32
catchI think we need to detect when the key is set when collecting entity info and trigger a deprecation then. If we did that we'd get errors for comment and forum. #2010202: Deprecate comment_uri().
Comment #35
longwaveMoved the patch to an MR, added deprecation notices on
getUriCallback()andsetUriCallback(), maybe we need more?Comment #36
longwaveDeprecated some more.
Comment #37
longwaveComment #39
godotislateComing here from #3301682-46: Define bundle classes via attributes, where I discovered that in the conversion from annotations to attributes, the
uri_callbackparameter was typed asstring|null, which made it impossible to specify class methods as theuri_callback, and that since that issue has never come up, pretty reasonable to conclude that it's almost never used.Anyway, MR looks good other needing a CR URL in all the deprecation messages. Good for RTBC once the CR is created and URLs are updated.
Comment #40
godotislateActually, caught one documentation reference in entity.api.php for
hook_entity_bundle_info()that probably should have a(deprecated)note on there somewhere. So back to NW for that and the CR.Comment #41
longwaveAdded a CR, updated all links. Also decided just to remove that reference in the API docs as nobody should be relying on
uri_callbackbeing returned any more anyway.Comment #42
godotislateDidn't notice before, but the MR target branch is 11.x, not main, so there are 1000 file changes showing.
Comment #43
godotislateMR and CR lgtm.
Comment #46
catchCommitted/pushed to main and 11.x, thanks!