You are here

function merci_line_item_field_formatter_view in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

Implements hook_field_formatter_view().

File

merci_line_item/merci_line_item.module, line 673
Defines the core MERCI line item entity and API functions interact with line items.

Code

function merci_line_item_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $result = array();

  // Collect the list of line item IDs.
  $line_item_ids = array();
  foreach ($items as $delta => $item) {
    $line_item_ids[] = $item['target_id'];
  }
  switch ($display['type']) {
    case 'merci_line_item_label':
      if ($line_item_ids) {
        $target_entities = entity_load('merci_line_item', $line_item_ids);
      }
      else {
        $target_entities = array();
      }
      foreach ($items as $delta => $item) {
        $line_item = $target_entities[$item['target_id']];
        $label = $line_item->line_item_label;
        $status = $line_item->{MERCI_CHECKOUT_STATUS}['und'][0]['value'];
        if (!array_key_exists($status, $result)) {
          $result[$status] = array();
        }

        // If the link is to be displayed and the entity has a uri, display a link.
        // Note the assignment ($url = ) here is intended to be an assignment.
        if ($display['settings']['link'] && ($uri = entity_uri($field['settings']['target_type'], $item['entity']))) {
          $result[$status][$delta] = array(
            '#markup' => l($label, $uri['path'], $uri['options']),
          );
        }
        else {

          //$result[$status][$delta] = array('#markup' => check_plain($label));
          $result[$status][$delta] = check_plain($label);
        }
      }
      $output = array();
      foreach ($result as $status => $fields) {
        $output[] = $status . ': ' . implode(', ', $fields);
      }
      $result = array();
      $result[0] = array(
        '#markup' => implode('<br>', $output),
      );
      break;
  }
  return $result;
}