Problem/Motivation
The token module introduces some pretty helpful tokens for the type menu-link. But it also provides tokens for the entity type menu_link_content which leads to 2 different sections in the token tree. And if the TokenEntityMapper service comes into play for the menu-link token type, this can get confusing quite easily.
Proposed resolution
Update the entity type info for menu_link_content just like for taxonomy terms.
Issue fork token-3314427
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:
Comments
Comment #3
jurgenhaasComment #4
berdirDoing that now is a BC change and I don't agree with it. menu links can be many things, not just menu_link_content and merging those two together is not correct and will not work as it won't be the entity object being passed. Beside, it will likely also stop generating base field tokens as there are already tokens for this.
Comment #5
jurgenhaasAgreed.
Well, "sometimes" it is. I came across the problem described in this issue in a pathauto scenario. When editing a node and providing a menu link, the token
menu-linkis passed in with data being\Drupal\menu_link_content\Entity\MenuLinkContent. However, when bulk updating pathauto with drush, the data being passed formenu-linkis an\Drupal\menu_link_content\Plugin\Menu\MenuLinkContentobject.I think, receiving a plugin rather than a content entity makes more sense, but I wasn't able to figure out why pathauto behaves differently here. Any ideas?
Comment #6
berdirtoken.module has a special computed field that supports changing the menu link as you save a node, that's probably why that behaves different. I wasn't aware that it passes in the entity.
token_tokens() has code that unifies it to the plugin object, you just just copy that as a quickfix if you have your own tokens.
Comment #7
jurgenhaasOK, found the code where the different data types get passed. It happens in
menu_ui_tokenscontained intoken.tokens.inc:When editing the node in the UI, the if-statement
($node->getFieldDefinition('menu_link') && $menu_link = $node->menu_link->entity)returns true and therefore uses the MenuLinkContentIniterface, i.e. the content entity.When using drush with bulk update, this if-statement returns FALSE and it uses the link from the menu_link_manager, i.e. a plugin.
Any idea, why the first version doesn't also load a plugin but the content entity instead?
Comment #8
berdir> Any idea, why the first version doesn't also load a plugin but the content entity instead?
No, and that is a change that I can get behind, so we would basically move/copy the logic in token_tokens() to that place.
Comment #9
jurgenhaasOK, I've changed the MR accordingly. Removed the original change and added the new one.
Comment #10
jurgenhaasI have updated the MR to work with the OO hooks.
Comment #11
berdirComment #13
berdirMerged.