Projet

Général

Profil

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

root / drupal7 / sites / all / modules / pathauto / pathauto.tokens.inc @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Token integration for the Pathauto module.
6
 */
7

    
8
/**
9
 * Implements hook_token_info().
10
 */
11
function pathauto_token_info() {
12
  $info = array();
13

    
14
  $info['tokens']['array']['join-path'] = array(
15
    'name' => t('Joined path'),
16
    'description' => t('The array values each cleaned by Pathauto and then joined with the slash into a string that resembles an URL.'),
17
  );
18

    
19
  return $info;
20
}
21

    
22
/**
23
 * Implements hook_tokens().
24
 */
25
function pathauto_tokens($type, $tokens, array $data = array(), array $options = array()) {
26
  $replacements = array();
27

    
28
  if ($type == 'array' && !empty($data['array'])) {
29
    $array = $data['array'];
30

    
31
    foreach ($tokens as $name => $original) {
32
      switch ($name) {
33
        case 'join-path':
34
          module_load_include('inc', 'pathauto');
35
          $values = array();
36
          foreach (element_children($array) as $key) {
37
            $value = is_array($array[$key]) ? render($array[$key]) : (string) $array[$key];
38
            $value = pathauto_cleanstring($value);
39
            $values[] = $value;
40
          }
41
          $replacements[$original] = implode('/', $values);
42
          break;
43
      }
44
    }
45
  }
46

    
47
  return $replacements;
48
}