Projet

Général

Profil

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

root / drupal7 / sites / all / modules / commerce / modules / order / commerce_order_ui.tokens.inc @ dbb0c974

1
<?php
2

    
3
/**
4
 * @file
5
 * Builds placeholder replacement tokens for UI bound order-related data.
6
 */
7

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

    
14
  // @deprecated since 7.x-1.2; use [commerce-order:customer-url] instead.
15
  $order['url'] = array(
16
    'name' => t('URL'),
17
    'description' => t('The URL of the order.'),
18
  );
19
  $order['customer-url'] = array(
20
    'name' => t('URL'),
21
    'description' => t('The URL for customers to view the order.'),
22
  );
23
  $order['admin-url'] = array(
24
    'name' => t('URL'),
25
    'description' => t('The URL for administrators to view the order.'),
26
  );
27
  return array(
28
    'tokens' => array('commerce-order' => $order),
29
  );
30
}
31

    
32
/**
33
 * Implements hook_tokens().
34
 */
35
function commerce_order_ui_tokens($type, $tokens, array $data = array(), array $options = array()) {
36
  $url_options = array('absolute' => TRUE);
37

    
38
  if (isset($options['language'])) {
39
    $url_options['language'] = $options['language'];
40
    $language_code = $options['language']->language;
41
  }
42
  else {
43
    $language_code = NULL;
44
  }
45

    
46
  $replacements = array();
47

    
48
  if ($type == 'commerce-order' && !empty($data['commerce-order'])) {
49
    $order = $data['commerce-order'];
50

    
51
    foreach ($tokens as $name => $original) {
52
      switch ($name) {
53
        // @deprecated since 7.x-1.2; use [commerce-order:customer-url] instead.
54
        case 'url':
55
        case 'customer-url':
56
          if ($uri = commerce_order_uri($order)) {
57
            $path = $uri['path'];
58
          }
59
          else {
60
            $path = 'user/' . $order->uid . '/orders/' . $order->order_id;
61
          }
62
          $replacements[$original] = url($path, $url_options);
63
          break;
64
        case 'admin-url':
65
          $replacements[$original] = url('admin/commerce/orders/' . $order->order_id, $url_options);
66
          break;
67
      }
68
    }
69
  }
70

    
71
  return $replacements;
72
}