You are here

function entity_reference_multiple_field_formatter_view in Entity Reference Multiple 7

Same name and namespace in other branches
  1. 7.2 entity_reference_multiple.module \entity_reference_multiple_field_formatter_view()

Implements hook_field_formatter_view().

File

./entity_reference_multiple.module, line 656
Primarily Drupal hooks.

Code

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

  // Rebuild the items list to contain only those with access.
  foreach ($items as $key => $item) {
    if (empty($item['access'])) {
      unset($items[$key]);
    }
  }
  switch ($display['type']) {
    case 'entity_reference_multiple_label':
      foreach ($items as $delta => $item) {
        $label = entity_label($item['target_type'], $item['entity']);

        // 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($item['target_type'], $item['entity']))) {
          $result[$delta] = array(
            '#markup' => l($label, $uri['path'], $uri['options']),
          );
        }
        else {
          $result[$delta] = array(
            '#markup' => check_plain($label),
          );
        }
      }
      break;
  }
  return $result;
}