You are here

function commerce_order_ui_tokens in Commerce Core 7

Implements hook_tokens().

File

modules/order/commerce_order_ui.tokens.inc, line 35
Builds placeholder replacement tokens for UI bound order-related data.

Code

function commerce_order_ui_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $url_options = array(
    'absolute' => TRUE,
  );
  if (isset($options['language'])) {
    $url_options['language'] = $options['language'];
    $language_code = $options['language']->language;
  }
  else {
    $language_code = NULL;
  }
  $replacements = array();
  if ($type == 'commerce-order' && !empty($data['commerce-order'])) {
    $order = $data['commerce-order'];
    foreach ($tokens as $name => $original) {
      switch ($name) {

        // @deprecated since 7.x-1.2; use [commerce-order:customer-url] instead.
        case 'url':
        case 'customer-url':
          if ($uri = commerce_order_uri($order)) {
            $path = $uri['path'];
          }
          else {
            $path = 'user/' . $order->uid . '/orders/' . $order->order_id;
          }
          $replacements[$original] = url($path, $url_options);
          break;
        case 'admin-url':
          $replacements[$original] = url('admin/commerce/orders/' . $order->order_id, $url_options);
          break;
      }
    }
  }
  return $replacements;
}