Projet

Général

Profil

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

root / drupal7 / sites / all / modules / i18n / i18n_node / i18n_node.tokens.inc @ 76df55b7

1
<?php
2

    
3
/**
4
 * @file
5
 * Builds placeholder replacement tokens for content types.
6
 */
7

    
8
/**
9
 * Implements hook_token_info().
10
 */
11
function i18n_node_token_info() {
12
  $content_type['i18n-name'] = array(
13
    'name' => t("Name (localized)"),
14
    'description' => t("The name of the content type."),
15
  );
16
  $content_type['i18n-description'] = array(
17
    'name' => t("Description (localized)"),
18
    'description' => t("The optional description of the content type."),
19
  );
20

    
21
  return array(
22
    'tokens' => array(
23
      'content-type' => $content_type,
24
    ),
25
  );
26
}
27

    
28
/**
29
 * Implements hook_tokens().
30
 */
31
function i18n_node_tokens($type, $tokens, array $data = array(), array $options = array()) {
32
  $replacements = array();
33
  $sanitize = !empty($options['sanitize']) ? TRUE : FALSE;
34
  $langcode = isset($options['language']) ? $options['language']->language : i18n_langcode();
35

    
36
  if ($type == 'content-type' && !empty($data['node_type'])) {
37

    
38
    $node_type = $data['node_type'];
39

    
40
    foreach ($tokens as $name => $original) {
41
      switch ($name) {
42

    
43
        case 'i18n-name':
44
          $name = array('node', 'type', $node_type->type, 'name');
45
          $options = array('sanitize' => $sanitize, 'langcode' => $langcode);
46
          $name = i18n_string_translate($name, $node_type->name, $options);
47
          $replacements[$original] = $name;
48
          break;
49

    
50
        case 'i18n-description':
51
          $description = array('node', 'type', $node_type->type, 'description');
52
          $options = array('sanitize' => $sanitize, 'langcode' => $langcode);
53
          $description = i18n_string_translate($description, $node_type->description, $options);
54
          $replacements[$original] = $description;
55
          break;
56
      }
57
    }
58
  }
59

    
60
  return $replacements;
61
}