• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

views.tokens.inc

Go to the documentation of this file.
00001 <?php
00002 
00011 function views_token_info() {
00012   $info['types']['view'] = array(
00013     'name' => t('View'),
00014     'description' => t('Tokens related to views.'),
00015     'needs-data' => 'view',
00016   );
00017   $info['tokens']['view']['name'] = array(
00018     'name' => t('Name'),
00019     'description' => t('The human-readable name of the view.'),
00020   );
00021   $info['tokens']['view']['description'] = array(
00022     'name' => t('Description'),
00023     'description' => t('The description of the view.'),
00024   );
00025   $info['tokens']['view']['machine-name'] = array(
00026     'name' => t('Machine name'),
00027     'description' => t('The machine-readable name of the view.'),
00028   );
00029   $info['tokens']['view']['title'] = array(
00030     'name' => t('Title'),
00031     'description' => t('The title of current display of the view.'),
00032   );
00033   $info['tokens']['view']['url'] = array(
00034     'name' => t('URL'),
00035     'description' => t('The URL of the view.'),
00036     'type' => 'url',
00037   );
00038 
00039   return $info;
00040 }
00041 
00045 function views_tokens($type, $tokens, array $data = array(), array $options = array()) {
00046   $url_options = array('absolute' => TRUE);
00047   if (isset($options['language'])) {
00048     $url_options['language'] = $options['language'];
00049   }
00050   $sanitize = !empty($options['sanitize']);
00051   $langcode = isset($options['language']) ? $options['language']->language : NULL;
00052 
00053   $replacements = array();
00054 
00055   if ($type == 'view' && !empty($data['view'])) {
00056     $view = $data['view'];
00057 
00058     foreach ($tokens as $name => $original) {
00059       switch ($name) {
00060         case 'name':
00061           $replacements[$original] = $sanitize ? check_plain($view->human_name) : $view->human_name;
00062           break;
00063 
00064         case 'description':
00065           $replacements[$original] = $sanitize ? check_plain($view->description) : $view->description;
00066           break;
00067 
00068         case 'machine-name':
00069           $replacements[$original] = $view->name;
00070           break;
00071 
00072         case 'title':
00073           $title = $view->get_title();
00074           $replacements[$original] = $sanitize ? check_plain($title) : $title;
00075           break;
00076 
00077         case 'url':
00078           if ($path = $view->get_url()) {
00079             $replacements[$original] = url($path, $url_options);
00080           }
00081           break;
00082       }
00083     }
00084 
00085     // [view:url:*] nested tokens. This only works if Token module is installed.
00086     if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
00087       if ($path = $view->get_url()) {
00088         $replacements += token_generate('url', $url_tokens, array('path' => $path), $options);
00089       }
00090     }
00091   }
00092 
00093   return $replacements;
00094 }

Generated on Sun Feb 26 2012 12:52:52 for Views by  doxygen 1.7.1