Skip to content

Instantly share code, notes, and snippets.

@stevesmename
Created December 17, 2014 22:02
Show Gist options
  • Save stevesmename/bf138fba371f1c1d13ad to your computer and use it in GitHub Desktop.
Save stevesmename/bf138fba371f1c1d13ad to your computer and use it in GitHub Desktop.
[file:description] token working with 'Download link' format
<?php
/**
* @file
* Token integration for the file_entity module.
*/
/**
* Implements hook_token_info().
*/
function hook_token_info() {
// File tokens.
$info['tokens']['file']['description'] = array(
'name' => t('File description'),
'description' => t('The description of the file.'),
'type' => 'file',
);
return $info;
}
/**
* Implements hook_tokens().
*/
function hook_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
$sanitize = !empty($options['sanitize']);
// File tokens.
if ($type == 'file' && !empty($data['file'])) {
$file = $data['file'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'description':
$replacements[$original] = $sanitize ? check_plain($file->description) : $file->description;
break;
}
}
}
return $replacements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment