You are here

function location_cck_token_values in Location 7.5

Same name and namespace in other branches
  1. 6.3 contrib/location_cck/location_cck.module \location_cck_token_values()
  2. 7.4 contrib/location_cck/location_cck.module \location_cck_token_values()

Implements hook_token_values().

File

contrib/location_cck/location_cck.module, line 535
Defines location field type.

Code

function location_cck_token_values($type, $object = NULL) {
  if ($type == 'field') {
    $tokens = array();
    $item = $object[0];
    if ($item['lid']) {

      // If the location exists, we need to set up the tokens.
      $location = array(
        // There is no way to find out which elements to hide because $item does not contain
        // the 'location_settings' element, so for now, just set it to be an empty array.
        // See http://drupal.org/node/463618 for more infomation.
        'hide' => array(),
        'location' => location_load_location($item['lid']),
      );

      // @@@ This is rather silly, but I can't think of anything better at the moment.
      $variables = array(
        'location' => $location,
      );
      template_preprocess_location($variables);
      $fields = location_field_names(TRUE);

      // @@@ We really need to rethink fields in location..
      unset($fields['locpick']);
      foreach ($fields as $k => $v) {
        if (isset($location[$k])) {
          $tokens[$k] = $location[$k];
        }
        else {
          $tokens[$k] = '';
        }
      }
    }
    return $tokens;
  }
}