Hello.

I would like to use the auto nodetitle module to create a title using the city and state values from the address field.

I tried using the tokens:

[field_facility_address_0_city-formatted]
[field_facility_address[0][city]-formatted]
[field_facility_address_0_city-raw]
[field_facility_address[0][city]-raw]

Unfortunately, none of those tokens work.

Has anyone tried to do this before?

Thanks.
-- Jason

Comments

rconstantine’s picture

Component: Miscellaneous » Code
Category: support » feature

I would like to know by what magic you are even coming up with those tokens since I have not implemented the token module hooks for this module.

I'm changing this to a feature request.

jsm174’s picture

The magic was just a pure "guess". My custom content type was called facility, and I was just using the format that other cck types use.

Anyway, I thought the module had token support and I was just missing something. I apologize.

I'll dig into the code and see if I can help out.

jsm174’s picture

I added the token functions and it's working for what I need. I'd like to submit a patch, but I need to do more research on the process.

Here is the code:

if (module_exists('token')) {
   function cck_address_token_list($type = 'all') {
      if ($type == 'field' || $type == 'all') {
         $tokens = array();

         $tokens['address']['street1'] = t("Address street1");
         $tokens['address']['street2'] = t("Address street2");
         $tokens['address']['apt'] = t("Address apt");
         $tokens['address']['city'] = t("Address city");
         $tokens['address']['state'] = t("Address state");
         $tokens['address']['zip'] = t("Address zip");
         $tokens['address']['country'] = t("Address country");
         $tokens['address']['other'] = t("Address other");

         return $tokens;
      }
   }

   function cck_address_token_values($type, $object = NULL, $options = array()) {
      if ($type == 'field') {
         $item = $object[0];

         $tokens['street1'] = $item['street1'];
         $tokens['street2'] = $item['street2'];
         $tokens['apt'] = $item['apt'];
         $tokens['city'] = $item['city'];
         $tokens['state'] = $item['state'];
         $tokens['zip'] = $item['zip'];
         $tokens['country'] = $item['country'];
         $tokens['other'] = $item['other'];

         return $tokens;
      }
   }
}
rconstantine’s picture

Status: Active » Needs review

Don't worry about a proper patch. Unlike some authors, I don't mind receiving clean code in the format you have presented. I am marking this post as patch (needs review) since I don't have time to look it over right now. Thanks for the contribution!

One thing you should do is to compare the code you wrote with that in my cck_fullname module which DOES have token support. There was a big stink a while ago about token hooks not being done properly which opened sites up to XSS issues. I think you may need to modify your cck_address_token_values function slightly by running the output through a filter IIRC.

jsm174’s picture

Great. Okay I added the check_plain() function. Thanks again!

Here is the updated code:

if (module_exists('token')) {
   function cck_address_token_list($type = 'all') {
      if ($type == 'field' || $type == 'all') {
         $tokens = array();

         $tokens['address']['street1'] = t("Address street1");
         $tokens['address']['street2'] = t("Address street2");
         $tokens['address']['apt'] = t("Address apt");
         $tokens['address']['city'] = t("Address city");
         $tokens['address']['state'] = t("Address state");
         $tokens['address']['zip'] = t("Address zip");
         $tokens['address']['country'] = t("Address country");
         $tokens['address']['other'] = t("Address other");

         return $tokens;
      }
   }

   function cck_address_token_values($type, $object = NULL, $options = array()) {
      if ($type == 'field') {
         $item = $object[0];

         $tokens['street1'] = check_plain($item['street1']);
         $tokens['street2'] = check_plain($item['street2']);
         $tokens['apt'] = check_plain($item['apt']);
         $tokens['city'] = check_plain($item['city']);
         $tokens['state'] = check_plain($item['state']);
         $tokens['zip'] = check_plain($item['zip']);
         $tokens['country'] = check_plain($item['country']);
         $tokens['other'] = check_plain($item['other']);

         return $tokens;
      }
   }
}
rconstantine’s picture

Status: Needs review » Reviewed & tested by the community

Yep. That should do it. I'll put this in the next release. Thanks again.

NewZeal’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Added to code for next commit