You are here

uc_payment.tokens.inc in Ubercart 8.4

Same filename and directory in other branches
  1. 7.3 payment/uc_payment/uc_payment.tokens.inc

Token hooks for the uc_payment module.

File

payment/uc_payment/uc_payment.tokens.inc
View source
<?php

/**
 * @file
 * Token hooks for the uc_payment module.
 */
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\uc_payment\Entity\PaymentMethod;

/**
 * Implements hook_token_info().
 */
function uc_payment_token_info() {
  $order['payment-method'] = [
    'name' => t('Payment method'),
    'description' => t('The payment method of the order.'),
  ];
  $order['payment-balance'] = [
    'name' => t('Balance'),
    'description' => t('The payment balance of the order'),
  ];
  return [
    'tokens' => [
      'uc_order' => $order,
    ],
  ];
}

/**
 * Implements hook_tokens().
 */
function uc_payment_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $values = [];
  if ($type == 'uc_order' && !empty($data['uc_order'])) {
    $order = $data['uc_order'];
    if (isset($tokens['payment-method'])) {
      $original = $tokens['payment-method'];
      $method = PaymentMethod::loadFromOrder($order);
      $values[$original] = $method ? $method
        ->getPlugin()
        ->cartReviewTitle() : t('Other');
    }
    if (isset($tokens['payment-balance'])) {
      $original = $tokens['payment-balance'];
      $values[$original] = uc_currency_format(uc_payment_balance($order));
    }
  }
  return $values;
}

Functions

Namesort descending Description
uc_payment_tokens Implements hook_tokens().
uc_payment_token_info Implements hook_token_info().