You are here

function file_entity_token_info in File Entity (fieldable files) 7.2

Same name and namespace in other branches
  1. 8.2 file_entity.tokens.inc \file_entity_token_info()
  2. 7.3 file_entity.tokens.inc \file_entity_token_info()
  3. 7 file_entity.tokens.inc \file_entity_token_info()

Implements hook_token_info().

File

./file_entity.tokens.inc, line 11
Token integration for the file_entity module.

Code

function file_entity_token_info() {

  // File type tokens.
  $info['types']['file-type'] = array(
    'name' => t('File type'),
    'description' => t('Tokens associated with file types.'),
    'needs-data' => 'file_type',
  );
  $info['tokens']['file-type']['name'] = array(
    'name' => t('Name'),
    'description' => t('The name of the file type.'),
  );
  $info['tokens']['file-type']['machine-name'] = array(
    'name' => t('Machine-readable name'),
    'description' => t('The unique machine-readable name of the file type.'),
  );
  $info['tokens']['file-type']['count'] = array(
    'name' => t('File count'),
    'description' => t('The number of files belonging to the file type.'),
  );
  $info['tokens']['file-type']['edit-url'] = array(
    'name' => t('Edit URL'),
    'description' => t("The URL of the file type's edit page."),
  );

  // File tokens.
  $info['tokens']['file']['type'] = array(
    'name' => t('File type'),
    'description' => t('The file type of the file.'),
    'type' => 'file-type',
  );
  $info['tokens']['file']['download-url'] = array(
    'name' => t('Download URL'),
    'description' => t('The URL to download the file directly.'),
    'type' => 'url',
  );
  if (module_exists('token')) {
    $info['types']['file_field'] = array(
      'name' => t('Media'),
      'description' => t('Tokens related to a file_entity field.'),
      'hidden' => TRUE,
    );
    $default_text = ' ' . t('Defaults to first value.');
    $info['tokens']['file_field'] = array(
      'field' => array(
        'name' => t('Field token value'),
        'description' => t('Default: The value returned by the token field formatter.') . $default_text,
      ),
      'url' => array(
        'name' => t('URL'),
        'description' => t('URL of the file_entity resource.') . $default_text,
        'type' => 'array',
      ),
      'filename' => array(
        'name' => t('Filename'),
        'description' => t('Filename the file_entity resource.') . $default_text,
        'type' => 'array',
      ),
      'filemime' => array(
        'name' => t('MIME type'),
        'description' => t('MIME type of the file_entity resource.') . $default_text,
        'type' => 'array',
      ),
      'type' => array(
        'name' => t('File type'),
        'description' => t('File type of the file_entity resource.') . $default_text,
        'type' => 'array',
      ),
      'image' => array(
        'name' => t('Image'),
        'description' => t('URL of a representative image for the file_entity resource, e.g. a video thumbnail.') . $default_text,
        'type' => 'array',
      ),
      'height' => array(
        'name' => t('Height'),
        'description' => t('Height of the file_entity resource, for videos or images.') . $default_text,
        'type' => 'array',
      ),
      'width' => array(
        'name' => t('Width'),
        'description' => t('Width of the file_entity resource, for videos or images.') . $default_text,
        'type' => 'array',
      ),
      'https-url' => array(
        'name' => t('Secure URL'),
        'description' => t('URL of the file_entity resource using HTTPS.') . $default_text,
        'type' => 'array',
      ),
      'https-image' => array(
        'name' => t('Secure image'),
        'description' => t('URL of a representative image for the file_entity resource using HTTPS, usually for videos.') . $default_text,
        'type' => 'array',
      ),
    );
    $all_fields = field_info_field_map();
    foreach ($all_fields as $field_name => $field) {
      if ($field['type'] == 'file') {
        $field_info = _token_field_info($field_name);
        foreach (array_keys($field['bundles']) as $entity_type) {
          if ($entity_type == 'taxonomy_term') {
            $entity_type = 'term';
          }
          $info['tokens'][$entity_type][$field_name] = array(
            'name' => $field_info ? $field_info['label'] : '',
            'description' => $field_info ? $field_info['description'] : '',
            'type' => 'file_field',
            'module' => 'file_entity',
          );
        }
      }
    }
  }
  return $info;
}