5 * Token integration for the views module.
9 * Implements hook_token_info().
11 function views_token_info() {
12 $info['types']['view'] = array(
14 'description' => t('Tokens related to views.'),
15 'needs-data' => 'view',
17 $info['tokens']['view']['name'] = array(
19 'description' => t('The human-readable name of the view.'),
21 $info['tokens']['view']['description'] = array(
22 'name' => t('Description'),
23 'description' => t('The description of the view.'),
25 $info['tokens']['view']['machine-name'] = array(
26 'name' => t('Machine name'),
27 'description' => t('The machine-readable name of the view.'),
29 $info['tokens']['view']['title'] = array(
31 'description' => t('The title of current display of the view.'),
33 $info['tokens']['view']['url'] = array(
35 'description' => t('The URL of the view.'),
43 * Implements hook_tokens().
45 function views_tokens($type, $tokens, array $data = array(), array $options = array()) {
46 $url_options = array('absolute' => TRUE
);
47 if (isset($options['language'])) {
48 $url_options['language'] = $options['language'];
50 $sanitize = !empty($options['sanitize']);
51 $langcode = isset($options['language']) ?
$options['language']->language
: NULL
;
53 $replacements = array();
55 if ($type == 'view' && !empty($data['view'])) {
56 $view = $data['view'];
58 foreach ($tokens as
$name => $original) {
61 $replacements[$original] = $sanitize ?
check_plain($view->human_name
) : $view->human_name
;
65 $replacements[$original] = $sanitize ?
check_plain($view->description
) : $view->description
;
69 $replacements[$original] = $view->name
;
73 $title = $view->get_title();
74 $replacements[$original] = $sanitize ?
check_plain($title) : $title;
78 if ($path = $view->get_url()) {
79 $replacements[$original] = url($path, $url_options);
85 // [view:url:*] nested tokens. This only works if Token module is installed.
86 if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
87 if ($path = $view->get_url()) {
88 $replacements += token_generate('url', $url_tokens, array('path' => $path), $options);