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.
Hi,
I just figured out, that tokens does not work in an image help text field!
All other help text fields seem to work just fine!
Best regards,
Tobi
Comment | File | Size | Author |
---|---|---|---|
#30 | tokens_in_field_help-1796024-30.patch | 679 bytes | hughworm |
| |||
#26 | tokens_in_field_help-1796024-26.patch | 2.62 KB | Tess Bakker |
#13 | tokdesctst.tgz | 5.19 KB | jacobfriis |
Comments
Comment #1
ryan_courtnage CreditAttribution: ryan_courtnage commented@DerTobi75, are you certain that it "All other help text fields seem to work just fine"? I can't get it working for any field.
@see http://drupal.stackexchange.com/questions/48483/drupal-7-tokens-in-field...
Comment #2
Dave ReidWhat tokens are you trying to use?
Comment #3
Dave ReidWill try to confirm shortly.
Comment #4
Dave ReidConfirmed. This is an issue with multiple-value fields, text fields, date fields, etc. I'm not finding any clear way that we can alter or futz with the description string in a reliable way that works on all fields and widgets. I'm wondering if I should just pull the 'support' from Token and try and push for the tokens in descriptions patch for core.
Comment #5
axe312 CreditAttribution: axe312 commentedPush! Still not working!
Comment #6
fugazi CreditAttribution: fugazi commentedConfirmed. This is an issue with multiple-value fields image
Comment #7
ciss CreditAttribution: ciss commentedJust thought I'd quickly provide our own workaround:
Comment #8
jacobfriis CreditAttribution: jacobfriis commentedThis ...-8.patch (against 7.x-1.x ~ >= 7.x-1.6) provides token replacement for all core field types' description (help text), plus date fields and field collections - and most likely a range of other fairly FAPI-faithful contrib/custom field types.
And multi-value'd instances are also supported.
The only known limitation so far is multi-value'd field_collection attached directly to an entity/node (not nested in another field collection). And that issue is probably a won't-fix, because the amount of code and static vars required to fix it would hardly justify the means (or an issue for the field collection project; a field collection - in that context - thinks it's parent is itself ;-).
The code doesn't assume well-formnedness API-wise from field instances (like: doesn't use values of array/object buckets unless it's certain they exist). Aborts gracefully if expectations aren't met.
The code also prioritizes performance: there's no need to do a lot of 'detective work' on the field at hand - and run the description string through a handful of expensive regexes (xss filtering and token scanning) - if the description definitely doesn't contain a token.
The algo is a spin-off from Localize Field (which translates field labels and descriptions) - thus a result of much FAPI reverse engineering, variable dumping and testing, testing, testing...
Really hope I haven't promised too much.
Comment #10
jacobfriis CreditAttribution: jacobfriis commentedChanged issue version to 7.x-1.6 (from 7.x-1.4) - though not sure if that's OK(?) - to make ...-8.patch applicable/testable.
Comment #12
jacobfriis CreditAttribution: jacobfriis commentedComment #13
jacobfriis CreditAttribution: jacobfriis commentedFeatures based module for human-aided testing.
It's node form - /node/add/tokdesctst - displays how many/which fields' descriptions don't get token replaced.
module: tokdesctst
node type: tokdesctst
field names: field_tokdesctst_*
tax vocabulary: tokdesctst
contrib dependencies: date, date_popup, features, field_collection
Comment #14
jacobfriis CreditAttribution: jacobfriis commentedComment #16
joelpittetprimaryly to primarily and doesn't need parenthesis.
Instead of the excessive nesting here maybe consider returning early at the top?
Maybe change this comment to a sentence or remove.
Why is this exploding a partial tag?
@todo?
Comment #17
jacobfriis CreditAttribution: jacobfriis commented@joelpittet Thx a mill for feedback.
But comment part replaced with 'but that normally doesn't get rendered.', which at least moves the POV from first person.
Comment #18
jacobfriis CreditAttribution: jacobfriis commentedComment #19
joelpittetYou're welcome, just a drive by review on my way to token vs entity_token duplication issue:)
Thanks for the quick fixes!.
One more and more context to #17.5
We don't do inline comments like this in coding standards.
May be worth moving this up to the top or to a relevant line it looks like it doesn't belong to anything (after thought)
Comment #20
geek-merlinStumbling across this, just fixed the notes from #19.
Code looks good, @jacobfriis thanks a lot for this.
(Academic note: i don't think the commented unset() lines are necessary as the ref is unset in the next return line anyway, but what the heck, php will optimize this away anyway then.)
Comment #21
geek-merlinCrosslinking related issue #2564437: Provide entity tokens in field help: Whichever gets in first, the other must be rebased.
Comment #22
jacobfriis CreditAttribution: jacobfriis commented@joelpittet Cleaned up according to #19 ;-)
@axel.rutz Aye, you're right, thx. Unsetting those references is obsolete. Overly paranoid about references. They are gone now ;-)
Comment #23
Tess BakkerHere are some small things I noticed:
something like..
see: element_get_visible_children
Comment #24
Tess BakkerOne other thing...
This patch won't work with i18n_field because i18n_field will translate the element description in the same hook.
In the current patch, the translated description will be overwritten by the original (instance) description.
Comment #25
Tess BakkerPatch with i18n support and works almost like the i18n description translation.
Comment #26
Tess BakkerSmall update, now without the double field_filter_xss()
Comment #27
jacobfriis CreditAttribution: jacobfriis commentedPatch #26 doesn't fix the issue for multi-valued fields.
Testable via the attached tokdesctst Features module.
You'd have to implement hook_preprocess_field_multiple_value_form() to fix that.
Patch #22 does handle multi-valued fields. However that patch isn't applicable anymore.
Hardcoding a call to another contrib module - i18n_field - into this module is sort of ugly.
So I'll be on my way, off this issue ;-)
Comment #28
paulwdru CreditAttribution: paulwdru commentedHi,
Does this issue relate to #2653768: Help Text of multi-value File field NOT translated if Token module is enabled ? Thanks
Comment #29
dedicated_hobby_coder CreditAttribution: dedicated_hobby_coder commentedHaven't tested for translations yet, (...) but will...
patch 26 did fix token support for address field help text in default language for me already.
p.s. i don't see any problem with the if statement
if (module_exists('i18n_field'))
how else to support translations?^^ Find it actually quite comforting to see it in there since I do develop a multilingual site.Will report back on token support in form translation when my project reaches the translation phase.
Thx for the patch ;-)
EDIT: Looks I spoke to soon for address field, since all address field help texts are now doubled^^ one time with toke replacement and a second time without replacement^^
Comment #30
hughworm CreditAttribution: hughworm as a volunteer commentedI needed this to work for a text field so I made a simple patch to token_field_widget_form_alter() in token.module to use the token-replaced value for "child elements", in this case "value". Works fine for my case, but haven't tested with image etc.