You are here

function merci_tokens in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.2

Implementation of hook_token_values().

See also

{merci_token_list}

File

./merci.module, line 753
MERCI - Managed Equipment Reservation Checkout and Inventory

Code

function merci_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'node' && !empty($data['node'])) {
    $node = $data['node'];

    //  $node = merci_load($object);
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'merci_resources':
          $titles = array();
          foreach ($node->merci_reservation_items as $did => $item) {
            if (empty($item['merci_item_nid']) and empty($item['type'])) {

              // Empty choice.
              continue;
            }
            if (!is_numeric($item['merci_item_nid'])) {

              // Unassinged bucket item.
              $item['type'] = $item['merci_item_nid'];
            }

            // Get the title of the item.
            $new_item = node_load($item['merci_item_nid']);
            if ($new_item) {
              $item['item_title'] = $new_item->title;
              $item['type'] = $new_item->type;
            }
            else {

              //TODO: should not be doing theming here.
              $content_settings = merci_load_item_settings($item['type']);
              $item['item_title'] = $content_settings->type_name;
            }
            $titles[] = $item['item_title'];
          }
          $replacements[$original] = check_plain(implode(", ", $titles));
          break;
      }
    }
  }
  return $replacements;
}