Problem/Motivation
Since the module requires Token module, let's make it a requirement.
Steps to reproduce
Install the Entity Prepopulate module, add the required tokens on the "manage fields" page for an Entity Reference from Url, and see that it doesn't work without the Token module.
Note also that "Browse available tokens." is missing on the "manage fields" page.
Proposed resolution
- Add Token module as a requirement in
epp.info.ymlto block installation, if Token is not available - Add a
composer.jsonfile as well, requiring the Token module
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork epp-3273749
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:
- 3273749-require-token-module
changes, plain diff MR !3
Comments
Comment #3
ressaComment #4
ressaComment #5
geek-merlinThanks for pointing this out. Alas, token service comes from core.
So please do it differently: Wrap all features that require token module in an if-clause.
Comment #6
ressaThanks for fast feedback. I am not sure how to fix it, so I hope some one else can step in, and do the required adjustments to the code.
Is it only in the case of Entity References from URL that the current version doesn't work, or also in other cases?
Comment #7
geek-merlinI'm sure the entity browser can't work, and usually (we can copy code from other modules) the code looks if token module is there, and if not, displays instructions.
You can test yourself: Remove the token-browser code, and report back what happens.
Comment #8
ressaSorry if I haven't explained the issue clearly enough: My main problem is that a reference field is not getting prepopulated if the Token module is not enabled. As soon as I enable the Token module, the field gets prepopulated. The missing "Browse available tokens." is a secondary issue.
I don't see any instructions at any point.
This is what I did:
target_id: '[current-page:query:test]'under "Entity Prepopulate"/node/add/chapter?test=3(an existing node ID) and saw no prepopulationEDIT: Reading your answer again, I think you did get it the first time :) So yes, your proposal of finding code elsewhere to display a Token module requirement under Entity Reference fields (if Token module is missing) makes sense.
Comment #9
geek-merlinThx! Yes: Token service comes from core, but SOME tokens (and the token browser) are only available with token module.
So techincally there id no dependency on token module. But some "premium" feature come from it.
There is a 10+ year old feature request to have modules "suggest" other modules, but it's not in yet.
But we can and should add a note in the module description in .info.yml. Feel free to update the MR with that.
Comment #10
ressaThanks for clarifying the situation, and that my observations were correct after all :)
But why can't Token be added as a requirement? I would consider entity reference support essential. As a case in point, it's used in the image on the project page. Also, in my mind, having no token browser available is a handicap, essentially making the user fly blind.
The Token module is the second most installed module, installed on 278,000 out of 430,000 +D8 installations, so it's not exactly obscure or un-maintained.
https://www.drupal.org/project/usage/drupal
https://www.drupal.org/project/usage/token
And by the way, I forgot to thank you for making this awesome module! Much simpler than the Prepopulate module.
Comment #11
geek-merlinBelieve me, i get angry rants when requiring something that is not technically necessary. And yes, maybe toke module should go core, and if you feel like, you can push that forward ;-).
Comment #12
ressaHeh, I believe you. It looks like #229568: [polilcy, no patch] Pathauto in core requires Token (or parts of it), so I am keeping my fingers crossed it will happen some day.
Yet, I just tried the epp module with Text (plain) field, a User field, a Number (integer) field and they all required Token module to work, like an entity reference field does.
So essentially, without the Token module, for which type of field does the module work?
Comment #13
geek-merlinI guess it's different: Not the field type, but what token you use is limited by the presence of token module.
Of course, without token browser and without use-the-source-luke-fu, it's difficult to know what tokens you have available.
Comment #14
geek-merlin"Pathauto requires token"... Nice!
Comment #15
geek-merlinBut on a systemic perspective, this all perfectly makes sense:
A german saying "The fist house you build for your foe, the second for your friend, the third for yourself."
So it's a good thing that often v1 and sometimes v2 happen in contrib, not in core. ;-)
Comment #16
ressaGreat saying! Though I am glad I practiced my Drupal skills on mostly my own projects in the beginning: "That module looks cool, let me add it". I have since become a follower of Ted Bowman's philosophy "There's a module for that! Don't use it!" :)
So, if Token module will not be required, should we check if the Token module is enabled, and if not, change the description? Perhaps something like this around line 90 in epp.module?
Comment #17
geek-merlinYes, that's exactly what i thought of.
The wording needs some tweaking though, instead of "to work" it's sth like "can use more tokens (link to docs page)".
If you roll a MR, great.
You can and should use this brand new feature to search how other modules do it. I guess this was copied a hundred times already.
#3051266: Searching for code across all of Gitlab
Comment #18
ressaI'll try to roll an MR, so thanks for the suggestion to use the new GitLab code search feature, it's a killer feature! And great idea to link to the documentation page. Would this be more precise?
Comment #19
geek-merlinYup!
Maybe "...for more information."
Comment #20
ressaI have created #3274425: Add Token module information, it was actually surprisingly easy.
Let's close this issue, and hope that Pathauto and Token gets into core eventually, at which point we can revisit this issue :)
Comment #21
ressa