Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
We have to port the token/devel integration.
Proposed resolution
We have to do it based on automatic but override-able entity link templates.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#15 | port_devel-2628298-15.patch | 16.79 KB | hussainweb |
| |||
#15 | interdiff-13-15.txt | 2.84 KB | hussainweb |
Comments
Comment #2
BerdirSee devel_entity_type_alter() for how I'd imagine this could work in 8.x
Comment #3
BerdirNote that this already exists in TokenDevelController, so we can possibly just remove the old code. And we should also be able to simplify this a lot and get rid of all those wrapper methods in there.
Comment #4
hussainwebI tested this with devel and it does not work at all. There was massive change required to get this working. I decided to split it and get devel integration at least working. We can add support for all entity types in a follow-up.
Comment #6
hussainwebAttempting a fix... The problem was that there is no devel which produced slightly different configurations in routes and tasks. This should make it more consistent.
Comment #7
BerdirLooks nice already, but lets just complete this and clean up the controller to support everything, should be easy, see below.
There is really no need for this additional complexity. Drop the entity type in the method name and argument, we have an entity object that knows the type. Then you can drop all the alias methods and have a single method for all entity types.
then you can already drop this check. However, you should add a check to not define the token-devel template if it's already set.
Comment #8
hussainwebStarting with a reroll to make sure we can get an interdiff later.
Comment #9
hussainwebFor comments in #7. I know it is not a lot of work to support all the entities, especially since the harder part is over. Still, I thought it simpler to stick to the scope and support what was possible in D7. I will attempt supporting other entities.
Comment #10
hussainwebOkay, the change was not really that trivial. The method in the route could not take entity directly as the entity type id in the path would not match the parameter name in the controller method and produced an error like this:
I changed it to use RouteMatch similar to devel and it works now.
(Above is only to document how to fix this. The patch works fine now.)
Comment #11
hussainwebRemoving the check and restructuring the if block a bit. I tested this manually again and it works.
Comment #12
BerdirI see, yes, that was a bit more complicated :)
Looks a lot nicer now, though, just a few small things and it should be good to go
* We can extend from ControllerBase, then we don't need the implements + string translation trait
* renderTokenTree is missing a docblock and should be protected
* entityLoad is a strange method name, I'd go with entityTokens or so.
* not here, but we should move _token_token_tree_format_row() also to the tree builder service I think. The goal is to get rid of .pages.inc IMHO :)
* "'data' => [$entity_type => $entity]," => this should use the token entity mapper, the key should be the token_type not, the entity type. otherwise it won't work for taxonomy_term's.
Comment #13
hussainwebAddressing points 1 and 2. I think the name is 'entityLoad' because it actually loads the entity from the RouteMatch and passes it on. I took it from devel. Of course, that doesn't mean it is right but I don't know what 'entityTokens' means. Can you reconsider the name?
As for the last point, should we do that in a follow-up? I didn't do anything there except change the array syntax. What do you think?
Comment #14
Berdiryes, it loads the entity, but that's just what it has to do to be able to do what it's actually about: *displaying tokens*, which is why I suggested entityTokens(). I haven't checked, but I'd guess devel calls it entityLoad() because it loads the entity and displays it, it probably also has entityRender/entityBuild or something like that.
I think we should fix the last point here, just means you need one more injected service and a method call there.
Comment #15
hussainwebI see what you mean by 'entityTokens', but it is still not that intuitive, IMHO. I think it is not that important, though. Changing that and also fixing the point about token_type.
Comment #16
BerdirHm, intuitive enough for me :) And agreed, not that important. committed, thanks!