Projet

Général

Profil

Paste
Télécharger (1,71 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / contexts / token.inc @ e4c061ad

1
<?php
2

    
3
/**
4
 * @file
5
 *  Provide a global context to allow for token support.
6
 */
7

    
8
$plugin = array(
9
  'title' => t('Token'),
10
  'description' => t('A context that contains token replacements from token.module.'),
11
  'context' => 'ctools_context_create_token',  // func to create context
12
  'context name' => 'token',
13
  'keyword' => 'token',
14
  'convert list' => 'ctools_context_token_convert_list',
15
  'convert' => 'ctools_context_token_convert',
16
);
17

    
18
/**
19
 * Create a context from manual configuration.
20
 */
21
function ctools_context_create_token($empty, $data = NULL, $conf = FALSE) {
22
  $context = new ctools_context('token');
23
  $context->plugin = 'token';
24

    
25
  return $context;
26
}
27

    
28
/**
29
 * Implementation of hook_ctools_context_convert_list().
30
 */
31
function ctools_context_token_convert_list() {
32
  $tokens = token_info();
33
  foreach ($tokens['types'] as $type => $type_info) {
34
    if (empty($type_info['needs-data'])) {
35
      $real_type = isset($type_info['type']) ? $type_info['type'] : $type;
36
      foreach ($tokens['tokens'][$real_type] as $id => $info) {
37
        $key = "$type:$id";
38
        if (!isset($list[$key])) {
39
          $list[$key] = $type_info['name'] . ': ' . $info['name'];
40
        }
41
      }
42
    }
43
  }
44

    
45
  return $list;
46
}
47

    
48
/**
49
 * Implementation of hook_ctools_context_converter_alter().
50
 */
51
function ctools_context_token_convert($context, $token) {
52
  $tokens = token_info();
53
  list($type, $token) = explode(':', $token, 2);
54
  $parts = explode(':', $token, 2);
55
  $real_type = isset($tokens['types'][$type]['type']) ? $tokens['types'][$type]['type'] : $type;
56
  if (isset($tokens['tokens'][$real_type][$parts[0]])) {
57
    $values = token_generate($type, array($token => $token));
58
    if (isset($values[$token])) {
59
      return $values[$token];
60
    }
61
  }
62
}