Created
December 17, 2014 22:02
-
-
Save stevesmename/bf138fba371f1c1d13ad to your computer and use it in GitHub Desktop.
[file:description] token working with 'Download link' format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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