1 date.tokens.inc date_token_info_alter(&$info)

Implements hook_token_info_alter().

File

core/modules/date/date.tokens.inc, line 37
Token module integration.

Code

function date_token_info_alter(&$info) {
  // Attach date field tokens to their respective entity tokens.
  $field_info = field_info_fields();
  $fields = _field_token_info();

  foreach ($fields as $field_name => $field) {
    if (in_array($field_info[$field_name]['type'], array('date', 'datetime', 'datestamp'))) {
      foreach (array_keys($field['bundles']) as $token_type) {
        // If a token already exists for this field, then don't add it.
        if (isset($info['tokens'][$token_type][$field_name])) {
          continue;
        }

        // Ensure token type for this entity already exists. 
        if (!isset($info['types'][$token_type]) || !isset($info['tokens'][$token_type])) {
          continue;
        }

        $info['tokens'][$token_type][$field_name] = array(
          // Note that label and description have already been
          // sanitized by _field_token_info().
          'name' => $field['label'],
          'description' => $field['description'],
          'module' => 'date',
          'type' => 'date-field-value',
        );

        if ($field_info[$field_name]['cardinality'] != 1) {
          $info['tokens'][$token_type][$field_name]['dynamic'] = TRUE;
          $info['tokens'][$token_type][$field_name]['description'] .= ' ' . t('Replace the ? with the delta for multi-value fields.');
        }

        if (empty($field_info[$field_name]['settings']['todate'])) {
          $info['tokens'][$token_type][$field_name]['type'] = 'date';
        }
      }
    }
  }
}