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.
It would be great if we could use tokens to access particular components of an address stored using Get Locations Fields. Currently there is a token available for the field as a whole, which seems much less useful.
Comment | File | Size | Author |
---|---|---|---|
#24 | Screenshot from 2015-08-25 11:29:15.png | 23.15 KB | cimo75 |
#6 | getlocations_fields.tokens2.txt | 4.46 KB | hutch |
#3 | getlocations_fields.tokens.txt | 4.45 KB | hutch |
Comments
Comment #1
hutch CreditAttribution: hutch commentedI know very little about Tokens, I can find docs that tell me I need a hook_token_info and a hook_tokens, there is an example_token module in the examples module but I do not have any idea how to test, if you can fill me in with details how to test a token and help with testing once I think I've got it that would help a lot.
Comment #2
mandclu CreditAttribution: mandclu commentedI can't speak generally about testing Tokens. I do tend to use tokens most often with Pathauto or rewriting the output of fields in Views. Woukd be happy to help with testing/troubleshooting.
Comment #3
hutch CreditAttribution: hutch commentedI have attached getlocations_fields.tokens.txt, this should be downloaded and the contents added to the end of getlocations_fields.module. Use current dev, that is what this has been developed on and be sure to flush the cache at least once.
The Views module has its own replacement tokens, these are available anyway. I used the Link module as I could test with it without wrecking the menu system which might/would have been the case with pathauto. A link field was added to a content type that also has a getlocations_fields instance and I used the link content textfield to test the token, that way nothing bad was likely to occur when I got it wrong which I did many times before it started to make sense.
It has been tested with nodes only, no other entities as yet but I have allowed for other entities that have getlocations_fields instances in them.
The tokens are formed in the following manner:
[<entity>:<field>:<item>:<delta>]
eg
[node:field_location:name:0]
The above assumes that the fieldname you have given the instance is "field_location" and will show the name field from the first map.
The following items are supported:
'name'
'street'
'additional'
'city'
'province'
'postal_code'
'latitude'
'longitude'
'country'
'country_name'
'phone'
'mobile'
'fax'
Please inform this issue on your testing experience!
Comment #4
mandclu CreditAttribution: mandclu commentedThanks for the quick turnaround! Just to confirm, should this work with either the 1.x or 2.x dev branch, or is there a specific one I should use for testing?
Comment #5
mandclu CreditAttribution: mandclu commentedI'm guessing it must have been developed for the 2.x branch. When I tested with 1.x-dev I got a fatal error:
Fatal error: Call to undefined function getlocations_get_supported_entities() in /Users/martin/Sites/budweisergardens/sites/all/modules/getlocations/modules/getlocations_fields/getlocations_fields.module on line 4895
Comment #6
hutch CreditAttribution: hutch commentedI tested on 1.x
I have fixed the typo in the included attachment.
I might work on 2.x but first things first
Comment #7
hutch CreditAttribution: hutch commentedWorks in 2.x dev as well. Will work in stable too I imagine.
Comment #8
mandclu CreditAttribution: mandclu commentedI can confirm that the code in #6 works as intended. I also tested omitting the delta and confirmed that it does indeed default to 0. Great work! I'd be happy to roll a patch if that would help.
Comment #9
hutch CreditAttribution: hutch commentedGood to have a confirmation, I will put the functions where I want them :-)
Tokens support has now been commited to 1.x dev and 2.x dev
Comment #10
cimo75 CreditAttribution: cimo75 commentedHi
7.x-1.x-dev can't get token to show up. They appear properly in the token browser but if I try to print any, none show up, using Display Suite fields and the DS input filter.
The tokens are copy and paste from the token browser, just exchanging the "?" for a "0". What am I missing here?
tx
Simone
Comment #11
hutch CreditAttribution: hutch commentedI eventually found a way to test this feature, using a module token_filter which adds token to formats in textarea boxes.
My test site works without this change but I think it might be the cause:
In getlocations_fields.functions.inc line 765 change:
to
Tested with
Where "field_location" is the machine name for a getlocations_fields instance in a content type.
Also tested street, country and country_name
Comment #12
cimo75 CreditAttribution: cimo75 commentedHi
I tried the fix and a number of tokens for the node, the current user and the user but none will display.
S.
Comment #13
hutch CreditAttribution: hutch commentedI should point out that there is no mention of support for the display suite module on the Token module's list of supporting modules. I did try the display suite on one occasion some time ago, it crashed the site and I had to roll back to backups so I won't be doing that again.
Comment #14
cimo75 CreditAttribution: cimo75 commentedHi,
I tried the Token Input Filter both on a block and on the body of a node but these tokens are not printed..
tx
S.
Comment #15
hutch CreditAttribution: hutch commentedMake sure you have enabled the token filter in a HTML format eg Full HTML
Comment #16
cimo75 CreditAttribution: cimo75 commentedYes I ve enabled it, although in the PHP input filter. What I am doing next is to set up a clean new install of Drupal and see how it goes there.
tx
S.
Comment #17
cimo75 CreditAttribution: cimo75 commentedOn a fresh install, node tokens work correctly but user and current-user don't work, I am loading them in a body field.
tx
Simone
Comment #18
cimo75 CreditAttribution: cimo75 commentedOnce again with a fresh install this is the body of a basic page node, you can see how the user related getlocation tokens are not rendered, i ve added a test field in the user fields and it does work:
Comment #19
cimo75 CreditAttribution: cimo75 commentedI can print properly the current user latitude like so:
Comment #20
hutch CreditAttribution: hutch commentedHere is a new version of function getlocations_fields_tokens fron getlocations_fields.functions.inc
This will support current-user and tokens like
[user:original:field_address:name:0]
"current-user" will work in node, "user" will not.
Comment #21
cimo75 CreditAttribution: cimo75 commentedOk working correctly on 7.x-1.x-dev ! Thanks for the support.
S.
Comment #22
hutch CreditAttribution: hutch commentedThe fix in #20 and some other stuff commited to getlocations-1.x-dev and getlocations-2.x-dev.
Comment #23
cimo75 CreditAttribution: cimo75 commentedHi
now I went back to the first site I was working on, I removed completely getlocations and readded the fields, I have same Token, Token Input, Getlocations Fields module, same Core Drupal, I analyzed the tables structure and it all seems fine there, same input filter. But in this site none of the Field Location tokens are printed ... I ve spent some time over this issue and I am at a loss, any idea?
tx
Simone
Comment #24
cimo75 CreditAttribution: cimo75 commentedHallo, good morning,;)
I tried to keep an eye open on the tokens being printed while I worked on the site but, at some point, the current-user tokens disappeared again.. and I am not sure what caused them to disappear so no big help on debugging at the moment.
After installing latest 7.x-1.x-dev from 25/08 I noticed this error too:
the only notice I keep getting is :
Comment #25
hutch CreditAttribution: hutch commentedThe section of code from line 2518 to line 2535 can be commented out, these are notices and do not interfere with the running. In my test rig current-user is working and node is working in nodes and user, current-user and user:original are working in user.
Comment #26
cimo75 CreditAttribution: cimo75 commentedYes that must be something along the way on this site that blocks the current-user token on nodes. I may try to disable modules one by one and see what happens, anyway I go the function I wanted (directions from current user to node) to work with the php snippet posted before, and it is working with DS fields so Display Suite can be used safely.
S.
Comment #27
hutch CreditAttribution: hutch commentedIf you want a map showing directions you could try the Getdirections module which supports Getlocations_fields in a variety of ways.
Comment #28
cimo75 CreditAttribution: cimo75 commentedYes that' s what I am using, a combination of the two modules.
S.
Comment #29
hutch CreditAttribution: hutch commentedIn that case see function getdirections_location_u2n_path in getdirections.api.inc which will give you a path printable in PHP if you have $uid and $nid.
Comment #30
cimo75 CreditAttribution: cimo75 commentedI did something like that:
Comment #31
albee CreditAttribution: albee commentedI have tested getlocations_fields.tokens2.txt and getlocations_fields.tokens.txt on 7x-1.17.dev I get this error
Fatal error: Cannot redeclare getlocations_fields_token_info() (previously declared in /sites/all/modules/getlocations/getlocations.module:8045) in /sites/all/modules/getlocations/modules/getlocations_fields/getlocations_fields.functions.inc on line 749
If i use 7x.1.16 module I get this Fatal error: Call to undefined function getlocations_get_supported_entities() in /sites/all/modules/getlocations/getlocations.module on line 7722
Comment #32
hutch CreditAttribution: hutch commentedPlease read the whole of this issue, the two functions were commited two years ago, see #22
You should always use a current version of Getlocations, either stable or dev
If you use the Token_filter module you will be able to use token placeholders in a body as suggested above.
eg
[node:field_location:country]
Comment #33
albee CreditAttribution: albee commentedThank you hutch. I've sorted it out. But.. [node:field_location:country] is not works... [node:field-location:country] works well. The different is _ & - There are both examples in tokens list.