1

I need to get the key of the key|value pair from a text list field in a token.

Say the field configuration shows the following options:

no|No Way Jose!
yes|Why yes, that'd do nicely!

and the field is named field_doc_textlist

the token [node:field_doc_textlist] is returning a value like 'No Way Jose!' when what I want is 'no'. Is there a way to get that from tokens. I'm using this in the filefield paths module if that matters.

I saw other similar answers here, with no real answers, but I've tried [node:field_doc_textlist:key] [node:field-doc-textlist] [node:field_doc_textlist:machine_name] [node:field_doc_textlist:machine-name] all to no avail

Some additional information: All of the above result in an error similar to

The File path is using the following invalid tokens: [node:field-doc-type-book].

A lot of the information I've found suggests using the hyphenated version of the token name instead of the underscore version, but that seems not to work at all.

  • I found the answer over here option to output key value for fields of "List (text)" type (oops pasted the wrong url before, not sure if you went there, fixed now.) – No Sssweat May 10 '16 at 1:25
  • Could you be more specific about what part of that you think will fix this? So far, nothing I'm trying is working. – UltraBob May 10 '16 at 2:23
  • did you try the sandbox module roborew's sandbox: Entity Token Display ? – No Sssweat May 10 '16 at 3:13
  • I hadn't tried that yet, because it meant I was going to need to go update a bunch of field instances, I guess I'll go try it now, and write a script to build the instances. – UltraBob May 10 '16 at 3:39
  • 1
    @NoSssweat. I did end up using that sandbox module and it worked. If you wouldn't mind quickly adding it to an answer I'll gladly accept. – UltraBob May 27 '16 at 0:04
1

You could use roborew's sandbox: Entity Token Display

This simple module was created to handle the formatting of entity tokens.

When using certain field entities the entity token module will provide formatting and data sanitisation for display. However, there are times when you need the default value of the original field.

1

Say you have field_textlist on node_mytype.

  • Go to admin/structure/types/manage/node-mytype/display and in the custom display settings tab, enable the token display mode
  • Go to admin/structure/types/manage/node-mytype/display/token, go to field_textlist and and set key as formatter
  • Use [node:field_textlist] (underscores) provided by token module, not [node:field-textlist] (dash) provided by entity api module.
  • Thanks, I'll have to check that out. I always kind of wondered about the token display because I couldn't see anywhere that is was actually affecting anything. – UltraBob Feb 28 '17 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.