I'm having trouble getting the module working with tokens, or more specifically field tokens. I have the following modules enabled (that are relevant):

Token 1.2 (tried 1.3 as well)
Custom formatters 2.2
Entity API 1.0-rc3 (with Entity tokens enabled)
CTools 1.2

When I create a new formatter, or edit the example html + token formatter, I don't have access to field tokens. They should logically be available under "node", but I only see field tokens such as [node:field_pck_img_overview] or [node:field-pck-img-overview:?]. None of them do anything at all. The example token formatter doesn't work either, but I figured I'm supposed to replace the tokens in the example with real tokens - however, those tokens are not available.

Am I missing something obvious here? I read in another issue where you (Deciphered) linked to a Token patch, but that patch is around two years old now.

Comments

Deciphered’s picture

Status: Active » Postponed

Unfortunately the Token-gate is still ever present, and is still not looking to be resolved even in Drupal 8, it is an unfortunate state of affairs.

I have looked at getting involved to get the issue fixed multiple times but there doesn't seem much that can be done at the moment.

alanom’s picture

Please, somewhere (project page? readme?) can you add a sentence or two stating clearly what is going on here? I've read about three issues on this now and I still don't know, other than that there is some problem. Does the tokens feature work? Does it work if this core patch is applied? What core patch is this? (I've seen a few oblique references to such a patch but haven't yet stumbled on an issue with a link). If the HTML/ tokens feature doesn't work because of a core issue, that's something that needs to be documented, so people know where they stand pre-install and so they know which core issue to follow (and what patches, if any, they might need to apply).

I can see that the image example included with the module includes tokens like [image-field-value:styles:url:thumbnail]. That's not a token syntax that matches anything in the tokens list, so I'm guessing custom formatters uses some kind of custom token syntax, which would explain why my attempts at using standard token syntax (e.g. [term:tid]) have all failed. What is this custom syntax? How, for example, would I apply it to a term id? If I guess wildly and try [tid-field-value] and it doesn't work, do I need to keep guessing syntax until I hit lucky, or will it never work because of "token-gate"?

p.s. the usability of this module would be enhanced greatly with the addition of:

  • On the tokens/HTML page, a simple note explaining the logic of the special token syntax used
  • On the PHP page, a simple note listing the local variables available within the scope of the inputted code, and/or a link to an appropriate API page giving more detail (e.g. if it is the scope of a hook, for example if it is the scope of hook_field_formatter_view(), a link to the API page of that hook - if nothing is available except the $variables variable, an API/documentation link on what it should contain would really help - but I've seen example code that uses $items?)
alanom’s picture

Component: Miscellaneous » Documentation
Category: support » task
Status: Postponed » Active

While this issue is postponed, it'd be really helpful if the status of the issue - what works, what doesn't - could be documented somewhere (with a link to "token-gate", perhaps). Thanks!

If I've understood it correctly, it sounds like one of the two interfaces of the module currently doesn't work for most (all?) cases.

Edit: just seen a comment from February 2012 in another thread that suggested you'd given up on what I'm guessing is "token-gate", implying you no longer expected the Tokens/HTML feature to work i.e. is deprecated? But other threads suggest it's under active development?

greenwork’s picture

This would change my use for custom_formatters if field tokens are not working. I am looking through the notes right now.

bcobin’s picture

Has there been any progress here either "up" or "down" as to whether HTML + Token will ever work again? I'm building a new site and I see it's broken with current code versions.

I used to use this a lot to simply insert SPAN tags in links that I could then hide and replace with an image - a very handy function that doesn't seem to be otherwise available.

Any news welcome - even if it's bad news... thanks!

erlendoos’s picture

I think this can be done by using hook_custom_formatters_token_data_alter(&$token_data, &$text, $field)

If you modify $text using $field you can make your own universal token.

Try this to see how to use this hook.

function MYMODULE_custom_formatters_token_data_alter(&$token_data, &$text, &$field) {
  dpm(array($token_data, $text, $field));
}

You can see which tokens are available by looking at a similar existing field. Note that some fields have a field_xxx and field-xxx variant.

Deciphered’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

Closing as duplicate of #1511830: Fix Token engine.