You are here

function field_tokens_token_info in Field tokens 7

Same name and namespace in other branches
  1. 8 field_tokens.tokens.inc \field_tokens_token_info()

Implements hook_token_info().

File

./field_tokens.tokens.inc, line 11
Token functions for Field tokens module.

Code

function field_tokens_token_info() {
  $field_types = field_info_field_types();
  $formatters = field_info_formatter_types();
  $types['field_property'] = array(
    'name' => t('Field properties'),
    'description' => t(''),
    'needs-data' => 'field_property',
  );
  $tokens['field_property']['?'] = array(
    'name' => t('Property name'),
    'description' => t('A property of the specified field; Replace \'?\' with a valid property for the specified field (e.g., value).'),
  );

  // Build token types for each field type.
  foreach ($field_types as $field_type_name => $field_type_info) {
    $types["formatted_field-{$field_type_name}"] = array(
      'name' => t('Formatted @label field', array(
        '@label' => $field_type_info['label'],
      )),
      'description' => t('Tokens related to Formatted @label fields.', array(
        '@label' => $field_type_info['label'],
      )),
      'needs-data' => "formatted_field-{$field_type_name}",
    );

    // Build tokens for each formatter of the current field type.
    foreach ($formatters as $formatter_name => $formatter_info) {
      if (in_array($field_type_name, $formatter_info['field types'])) {
        $tokens["formatted_field-{$field_type_name}"]["{$formatter_name}"] = array(
          'name' => $formatter_info['label'],
          'description' => t('@label formatter.', array(
            '@label' => $formatter_info['label'],
          )) . ' ',
          'dynamic' => TRUE,
        );

        // Adjust token name and description if formatter has no settings.
        if (empty($formatter_info['settings'])) {
          $tokens["formatted_field-{$field_type_name}"]["{$formatter_name}"]['description'] .= t('Has no settings.');
          unset($tokens["formatted_field-{$field_type_name}"]["{$formatter_name}"]['dynamic']);
        }
        else {
          $settings = array();
          foreach ($formatter_info['settings'] as $key => $default) {
            $settings[] = $key;
          }
          $tokens["formatted_field-{$field_type_name}"]["{$formatter_name}"]['description'] .= t('Replace \'?\' with formatter settings in the following format: \'SETTING-VALUE:SETTING-VALUE-...\'.<br /> Available settings: @settings', array(
            '@settings' => implode(', ', $settings),
          ));
        }
      }
    }
  }
  return array(
    'types' => $types,
    'tokens' => $tokens,
  );
}