You are here

function merci_line_item_tokens in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2

Implements hook_tokens().

File

modules/merci_line_item/merci_line_item.tokens.inc, line 41
Builds placeholder replacement tokens for merci_line_item-related data.

Code

function merci_line_item_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $token_service = \Drupal::token();
  $url_options = [
    'absolute' => TRUE,
  ];
  if (isset($options['langcode'])) {
    $url_options['language'] = \Drupal::languageManager()
      ->getLanguage($options['langcode']);
    $langcode = $options['langcode'];
  }
  else {
    $langcode = LanguageInterface::LANGCODE_DEFAULT;
  }
  $replacements = [];
  if ($type == 'merci_line_item' && !empty($data['merci_line_item'])) {

    /** @var \Drupal\merci_line_item\NodeInterface $merci_line_item */
    $merci_line_item = $data['merci_line_item'];
    foreach ($tokens as $name => $original) {
      switch ($name) {

        // Simple key values on the merci_line_item.
        case 'id':
          $replacements[$original] = $merci_line_item
            ->id();
          break;
        case 'label':
          $replacements[$original] = $merci_line_item
            ->label();
          break;
      }
    }
  }
  return $replacements;
}