You are here

function location_cck_token_info in Location 7.3

Implements hook_token_info().

File

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

Code

function location_cck_token_info() {
  $info = array();

  // Load all available fields.
  // In Drupal 7.22 the field_info_field_map() function was added, which is more
  // memory-efficient in certain cases than field_info_fields().
  // @see https://drupal.org/node/1915646
  $field_map_available = version_compare(VERSION, '7.22', '>=');
  $entities = $field_map_available ? field_info_field_map() : field_info_fields();

  // Loop through our fields and remove all but location types.
  foreach ($entities as $key => $value) {
    if ($value['type'] != 'location') {
      unset($entities[$key]);
    }
  }

  // If we have location fields available, setup our tokens.
  if (sizeof($entities)) {

    // Get the available location field names.
    $fields = location_field_names(TRUE);

    // Loop through the location fields and setup tokens.
    foreach ($entities as $key => $value) {
      $info['tokens']['node'][$key] = array(
        'name' => t('Location field: !field', array(
          '!field' => $key,
        )),
        'description' => t('Tokens for the field: !field. Replace the "?" with the delta you want. Defaults to delta 0.', array(
          '!field' => $key,
        )),
        'type' => $key,
      );
      $info['types'][$key] = array(
        'name' => t('Location field: !field', array(
          '!field' => $key,
        )),
        'description' => t('Tokens for the field: !field. Replace the "?" with the delta you want. Defaults to delta 0.', array(
          '!field' => $key,
        )),
        'needs-data' => 'node',
      );
      foreach ($fields as $field_key => $field_value) {
        $info['tokens'][$key][$field_key . ":?"] = array(
          'name' => t($field_value),
          'description' => t($field_value),
        );
      }
    }
  }
  return $info;
}