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

  1. Add Token module as a requirement in epp.info.yml to block installation, if Token is not available
  2. Add a composer.json file as well, requiring the Token module

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork epp-3273749

Command icon 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

ressa created an issue. See original summary.

ressa’s picture

Issue summary: View changes
ressa’s picture

Status: Active » Needs review
geek-merlin’s picture

Status: Needs review » Needs work

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

ressa’s picture

Issue summary: View changes

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

geek-merlin’s picture

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

ressa’s picture

Issue summary: View changes

Sorry 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:

  1. Added a new content type "Chapter"
  2. Added a new field, Reference > Content called "Main article"
  3. Selected "Article" under Reference type > Content type
  4. Added target_id: '[current-page:query:test]' under "Entity Prepopulate"
  5. Went to /node/add/chapter?test=3 (an existing node ID) and saw no prepopulation
  6. Enabled Token module, and the field was prepopulated

EDIT: 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.

geek-merlin’s picture

Component: Code » Documentation
Category: Bug report » Task

Thx! 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.

ressa’s picture

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

geek-merlin’s picture

Believe 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 ;-).

ressa’s picture

Heh, 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?

geek-merlin’s picture

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

geek-merlin’s picture

"Pathauto requires token"... Nice!

geek-merlin’s picture

But 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. ;-)

ressa’s picture

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

if "Token module enabled" {
  $description = t('For Entity Prepopulation to work and Token browser access, please install the Token module.');
  } else {
  $description = t('The values will only be applied if all tokens are replaced. If the value is not valid, no replacement will happen. You can use Yaml syntax to target field properties. You can use tokens.');
}

$form['third_party_settings']['epp']['value'] = [
  '#description' => $description,
geek-merlin’s picture

Yes, 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

ressa’s picture

I'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?

For more tokens and Token browser access, please install the Token module. See the documentation for more.

geek-merlin’s picture

Yup!

Maybe "...for more information."

ressa’s picture

Status: Needs work » Closed (won't fix)

I 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 :)

ressa’s picture