Comments

tonycpsu’s picture

Subscribing

rooby’s picture

Marked #1097356: Provide location tokens as duplicate of this.

Anonymous’s picture

Has this been solved? I still don't see any tokens in the URL aliases.

+

j_ten_man’s picture

StatusFileSize
new6.46 KB

Here is the file that handles location tokens. Just drop this in the location module and it rename it to location.tokens.inc (remove the .txt extension). Clear your cache and it should work. To fully clean up the old code, you should delete the location.token.inc file and remove the calls made to it in the location.module.

Anonymous’s picture

Works like a charm!
Thanks j_ten_man.

podarok’s picture

can You provide a patch in git format?

j_ten_man’s picture

StatusFileSize
new6.79 KB

Hopefully I did that right.

beckyjohnson’s picture

When I added this file, I got tokens that looked like this: [node:location:city:?] and consequently, that didn't work......

I wonder if this is a problem with old code lingering around. What files do I need to delete old code from? It was unclear for me, when I read the above.

j_ten_man’s picture

This is the new dynamic way for tokens to work. Try using [node:location:city] which is the same as [node:location:city:0] to get the city.

beckyjohnson’s picture

OK, i'll try it again. I just thought the question mark that was showing up was indicative of a problem...

ipndrmath’s picture

When using either [node:location:city:0] or [node:location:city] I recieve the notice:

Notice: Undefined property: stdClass::$location in location_tokens() (line 103 of /var/www/drupal/drupal-7.8/sites/default/modules/location/location.tokens.inc).

The token then does not resolve and leaves me with the token text rather than the token value. I am attempting to use the tokens with Automatic Nodetitles.

Any thoughts? Thanks!

gazwal’s picture

Subscribing

jboeger’s picture

subscribing.

j_ten_man’s picture

StatusFileSize
new6.88 KB

I think this should fix the issue in #11.

bryancasler’s picture

Thanks so much for this. I see the option for [account:location], are we able to do [account:location:city] to get the separate fields?

bryancasler’s picture

I just tried using [account:location] and only the raw token shows up.

j_ten_man’s picture

You'd definitely need to use [account:location:city] or [account:location:name] in order to use location tokens.

[account:location] won't be replaced. You need to go further down.

bryancasler’s picture

Thanks j_ten_man. What would be the full list of those tokens. Is it this?

[account:location:name]
[account:location:street]
[account:location:additional]
[account:location:city]
[account:location:province]
[account:location:postal_code]
[account:location:country]

j_ten_man’s picture

@animelion - all of those you listed plus:
[account:location:province_name]
[account:location:latitude]
[account:location:longitude]
[account:location:country_name]

LTech’s picture

I've put the code in the file sites/all/modules/location/location.token.inc and deleted the old location/token.inc file.
Then I commented out in sites/all/modules/location/location.module:
/**
* Implements hook_token_values().

function location_token_values($type, $object = NULL) {
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'location') . '/location.token.inc');
return _location_token_values($type, $object);
}
*/
/**
* Implements hook_token_list().

function location_token_list($type = 'all') {
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'location') . '/location.token.inc');
return _location_token_list($type);
}
*/
I cleared the cache but I still don't see location: options under URL aliases/patterns replacement patterns -> nodes
I have cck fields locations fields that I want to use in the URL.
What am I doing wrong?
Thanks so much

wprunella’s picture

Does this patch only work for Node Location fields? I am using Location CCK and I cannot get this patch to work.
Locations tokens do not show.
There are no error messages.

wprunella’s picture

For others who are having trouble with this patch.
Node Locations works.
Location CCK does not work.

LTech’s picture

Thanks for letting us know. Is there anyway to do it with Location CCK?

aniebel’s picture

Just as an FYI... Not sure if this is relative to this or not but I don't see tokens for individual fields (phone, address, state, etc) in Views after applying this patch.

rubenlor’s picture

StatusFileSize
new21.63 KB

I managed to modify location_cck.module, this is the first step, this is not fine

sol roth’s picture

Anyone get user location tokens to work correctly?? I'm trying to get them to show up in Panels title (manually set or from pane) and even though I can see "%user:location" in the substitutions menu. It does not show up. I tired drilling down farther into %user:location:city and %user:location:city:0, but those do not show up either.

Refineo’s picture

Status: Active » Needs work

@rubenlor, the attachment in #25 is in a wrong format. It is probably a modified location_cck.module, not a diff patch (like the patch in #14), isn't it?
Can you please provide a patch in the diff patch format ?

bryancasler’s picture

+1 for anyone who can help with a proper patch

Refineo’s picture

OK, here is the patch based on the #25 and the latest location_cck.module 7.x-3.x-dev.
This still needs work and cleaning the code.

bryancasler’s picture

Applied the patch in #29 but I don't think it's workings, or at lease these tokens no longer work.

[account:location:street], [account:location:city], [account:location:province] [account:location:postal_code]
doublejosh’s picture

REMOVING, unrelated

doublejosh’s picture

REMOVING, unrelated

jghyde’s picture

I am a bit confused. The attached location.tokens.inc_.txt to #4 fixed my problem. However, this thread is diverging from node location to cck location.

#4 appears to fix the NODE location. As for the rest...

None of the patches patched anything for me. But the patch threw no errors, only silence.

doublejosh’s picture

My fault. Please ignore.
Totally unrelated.

miaoulafrite’s picture

hello there!
any news for location cck and 7.x-3.x-dev?

bnicoll’s picture

#7 - Patch - Brilliant - Thankyou!!!

podarok’s picture

Status: Needs work » Patch (to be ported)

from #36

steven.wichers’s picture

Patches in #25/#29 for location_cck seem to be just the token code copied from location. The function names aren't correct and have a hard-coded field name.

rooby’s picture

Status: Patch (to be ported) » Needs work

No need for porting the patch, it is for drupal 7 only.

Sorry for not looking at this earlier, I will have a proper look later but at first glance:

hook_token_list() and hook_token_values() are drupal 6 functions and are not required in drupal 7.

Drupal 7 only requires, hook_token_info() and hook_tokens().

For an example see the Examples module example - http://drupalcode.org/project/examples.git/blob/refs/heads/7.x-1.x:/toke...

Rechi’s picture

Any updates on token support for cck location 7.x-3.x?
Thank you for your hard work.

aaronbauman’s picture

problems with patch 29:

  • implements location_token_info() and location_tokens() in location_cck module. these functions should be in location.token.inc, and location_cck_token_info() and location_cck_tokens() should be in location_cck.module.
  • hard-codes "node", "field_location", "und" and "0", instead of offering token support for arbitrary entities, fields, languages, and deltas
  • only includes a subset of a location instance's columns -- street, city, province name, post code, country name -- instead of all a location's columns
  • comments out old hook implementations, rather than removing them
  • spacing
LiloLilo’s picture

+1 subscribing for Location CCK tokens support. Any news? Is there a working patch or dev release? Thanks

rooby’s picture

#39 & #41 have still not been addressed since the patch in #29.

rooby’s picture

Assigned: Unassigned » rooby

I'll put some time in here.

rooby’s picture

I've done a fair bit of this however it seems we are blocked until this issue is resolved:
#1195874: Need to figure out how to create nested tokens from the array token type

Reason being is that we need a structure like this:
node:locations:value:0:country
user:locations:value:0:province

That kind of structure is not possible with the current token module (array tokens are provided by the token module, they aren't part of core tokens).

If an entity could only have a single location we would be ok but that isn't the case.

I will properly check out the progress of that ticket soon and see what I can do here.

jibus’s picture

The patch provided in #14 seems to work for Location node.

Would it be possible to commit this ?

marianojp’s picture

Hi Jibus,

Can Anyone help me? I tried all the patches but still not working.

strykaizer’s picture

Patch #14 works for me (Used it to add location related data in url alias)

Thx!

Ether’s picture

Any chance that token support for Location CCK will be in dev version soon ?

jibus’s picture

Any news on this ?

podarok’s picture

Status: Needs work » Needs review

bot?

Status: Needs review » Needs work

The last submitted patch, location_cck-token-support-1056154-29.patch, failed testing.

podarok’s picture

the patch needs reroll

rooby’s picture

Assigned: rooby » Unassigned

Sorry, I somehow missed the old patch in #14. I so wish drupal.org had some sort of flag functionality for bookmarking important issues.

Also, the issue referenced in #45 is unlikely to get fixed any time soon I would say, so maybe an alternative for now could be to implement something like the subscriptions module has, as mentioned in #1195874-26: Need to figure out how to create nested tokens from the array token type.

Unassigning myself as I have not had time to work on this since #45.

jibus’s picture

The patch provided in #14 works for the general location module.

The patch #25 & #29 are for the submodule CCK location module and needs some love.

Should we create an other issue regarding tokens in CCK location module ?

podarok’s picture

Status: Needs work » Needs review

#14: token-support-1056154-14.patch queued for re-testing.

podarok’s picture

to #55
We can handle #25 and ##29 here after #14 commited or if You want to give love for those patches by youself You can create follow-up issues to this )

podarok’s picture

Category: feature » bug

#14 commited pushed to 7.x-3.x-dev

#25 and #29 still need some love

Thanks!
tagged as Needs test for #14

http://drupal.org/node/1942736 tagged in alpha release

podarok’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
+++ b/sites/all/modules/contrib/location/contrib/location_cck/location_cck.moduleundefined
@@ -514,27 +515,36 @@ function theme_location_cck_field_popup($variables) {
+    if ($type == 'field' || type == 'all') {
+    ¶
+++ b/sites/all/modules/contrib/location/contrib/location_cck/location_cck.moduleundefined
@@ -514,27 +515,36 @@ function theme_location_cck_field_popup($variables) {
     unset($fields['locpick']);
+    ¶
+    ¶
+++ b/sites/all/modules/contrib/location/contrib/location_cck/location_cck.moduleundefined
@@ -514,27 +515,36 @@ function theme_location_cck_field_popup($variables) {
-    return $tokens;
+   ¶
+++ b/sites/all/modules/contrib/location/contrib/location_cck/location_cck.moduleundefined
@@ -514,27 +515,36 @@ function theme_location_cck_field_popup($variables) {
+  ¶
     $tokens = array();
+  if ($type == 'field' || $type == 'all') ¶
+      {
     $item = $object[0];
+++ b/sites/all/modules/contrib/location/contrib/location_cck/location_cck.moduleundefined
@@ -563,11 +573,125 @@ function location_cck_token_values($type, $object = NULL) {
+    ¶
   }
+++ b/sites/all/modules/contrib/location/contrib/location_cck/location_cck.moduleundefined
@@ -563,11 +573,125 @@ function location_cck_token_values($type, $object = NULL) {
+}
+ * ¶
+++ b/sites/all/modules/contrib/location/contrib/location_cck/location_cck.moduleundefined
@@ -563,11 +573,125 @@ function location_cck_token_values($type, $object = NULL) {
+    'description' => t('Tokens related to location.'),
+  ¶

a lot of trailing whitespace errors for #29 http://drupal.org/coding-standards#indenting despite the fact that patch do not applies against latest dev

rooby’s picture

I'll see if I can dig up the version I was working on in #45 before I hit the road block and compare it to the others we have here.

rooby’s picture

Found it, but it turns out that it was basically a duplicate of the one in #14.
Silly me for not paying more attention.

rooby’s picture

#25 is not a patch.

#29 needs a re-roll as mentioned by podarok.

In addition to that I had a quick look through and:

+++ b/sites/all/modules/contrib/location/contrib/location_cck/location_cck.module
@@ -119,7 +119,8 @@ function location_cck_field_settings($op, $field) {
-        'field' => 'lid',
+        //'field' => 'lid',
+        'field' => $field_alias,

Is this related to tokens?

+++ b/sites/all/modules/contrib/location/contrib/location_cck/location_cck.module
@@ -514,27 +515,36 @@ function theme_location_cck_field_popup($variables) {
 /**
  * Implements hook_token_list().
  */
+/*
 function location_cck_token_list($type = 'all') {
-  if ($type == 'field') {
-    $tokens = array();
+  $tokens = array();
+    if ($type == 'field' || type == 'all') {
+    ¶
 
     $fields = location_field_names(TRUE);
     // @@@ We really need to rethink fields in location..
     unset($fields['locpick']);
+    ¶
+    ¶
     foreach ($fields as $k => $v) {
       $tokens['location'][$k] = $v;
     }
 
-    return $tokens;
+   ¶
   }
-}
 
+   return $tokens;
+}
+*/
 /**
  * Implements hook_token_values().
  */
+/*
 function location_cck_token_values($type, $object = NULL) {
-  if ($type == 'field') {
+  ¶
     $tokens = array();
+  if ($type == 'field' || $type == 'all') ¶
+      {
     $item = $object[0];
     if ($item['lid']) {
       // If the location exists, we need to set up the tokens.
@@ -563,11 +573,125 @@ function location_cck_token_values($type, $object = NULL) {

@@ -563,11 +573,125 @@ function location_cck_token_values($type, $object = NULL) {
         }
       }
     }
-    return $tokens;
+    ¶
   }
+  return $tokens;
+
+}
+ * ¶

These should be deleted instead of commented out.

+++ b/sites/all/modules/contrib/location/contrib/location_cck/location_cck.module
@@ -563,11 +573,125 @@ function location_cck_token_values($type, $object = NULL) {
+                    $replacements[$original] = $data["node"]->field_location["und"][0]["street"];
+                    break;
+                 case 'city':
+                    $replacements[$original] = $data["node"]->field_location["und"][0]["city"];
+                    break;
+                case 'province_name':
+                    $replacements[$original] = $data["node"]->field_location["und"][0]["locpick"]["province_name"];
+                    break;
+                case 'postal_code':
+                    $replacements[$original] = $data["node"]->field_location["und"][0]["postal_code"];
+                    break;
+                case 'country_name':
+                    $replacements[$original] = $data["node"]->field_location["und"][0]["locpick"]["country_name"];
+                    break;
+            }

This part should not use hard coded field name & langauge.

For reference, you can see how field_tokens uses dynamic language & field names.

Also, there should be more tokens than that.

podarok’s picture

Category: bug » feature

anyway this is a feature request )

rooby’s picture

Category: bug » feature

It is a regression from drupal 6 though.

podarok’s picture

Category: feature » bug

woops

sanjay.soni’s picture

Status: Needs work » Needs review

#14: token-support-1056154-14.patch queued for re-testing.

podarok’s picture

Status: Needs review » Needs work

Latest one needs work

pfrilling’s picture

Status: Needs work » Needs review
StatusFileSize
new4.65 KB

Attached is a patch that I have working for this feature request. I removed the hook_token_list() and hook_token_value() functions and replaced them with hook_token_info() and hook_tokens() functions.

The patch creates a new token for each location field in the database. So if you have more than one location field created, a new token will be generated for each field.

podarok’s picture

Status: Needs review » Needs work

Please, Upload patch in git diff format http://drupal.org/patch
Not in txt

pfrilling’s picture

Status: Needs work » Needs review
StatusFileSize
new4.65 KB

Sorry about that. I renamed the file and re-attached.

podarok’s picture

Status: Needs review » Fixed

#70 commited pushed to 7.x-3.x
Patch has a lot of whitespace errors!!!

tvasilia’s picture

Just a minor question about the last committed patch:
It gives me warnings when importing feeds with location_cck fields... More specifically, I tracked the problem down to this point in code:

function location_cck_tokens (hook_tokens implementation)
......
    // Loop through the tokens.
    foreach ($tokens as $name => $original) {
      // Break our token into an array to use later.
      $fields = explode(':', $name);
      $entity = $fields[0];
      $field = $fields[1];

According to the API, the $tokens is structured as [machinename] => [type:token]...
However, this code above assumes that $name (i.e. the key of the $tokens array) has the colon character ":" for exploding...
This gives an error because obviously $fields[1] has an undefined index...

Can you please take a look ?
I assume that explode function must be applied to the $original instead of the $name

Thanks for your efforts.

podarok’s picture

#72 looks like a follow-up bug
Please fill it...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.