public function Field::getItems

Return an array of items for the field.

File

drupal/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php, line 688
Definition of Drupal\field\Plugin\views\field\Field.

Class

Field
A field that displays fieldapi fields.

Namespace

Drupal\field\Plugin\views\field

Code

public function getItems($values) {
  $original_entity = $this
    ->getEntity($values);
  if (!$original_entity) {
    return array();
  }
  $entity = $this
    ->process_entity($original_entity);
  if (!$entity) {
    return array();
  }
  $display = array(
    'type' => $this->options['type'],
    'settings' => $this->options['settings'],
    'label' => 'hidden',
    // Pass the View object in the display so that fields can act on it.
    'views_view' => $this->view,
    'views_field' => $this,
    'views_row_id' => $this->view->row_index,
  );
  $langcode = $this
    ->field_langcode($entity);
  $render_array = field_view_field($entity, $this->definition['field_name'], $display, $langcode);
  $items = array();
  if ($this->options['field_api_classes']) {

    // Make a copy.
    $array = $render_array;
    return array(
      array(
        'rendered' => drupal_render($render_array),
      ),
    );
  }
  foreach (element_children($render_array) as $count) {
    $items[$count]['rendered'] = $render_array[$count];

    // field_view_field() adds an #access property to the render array that
    // determines whether or not the current user is allowed to view the
    // field in the context of the current entity. We need to respect this
    // parameter when we pull out the children of the field array for
    // rendering.
    if (isset($render_array['#access'])) {
      $items[$count]['rendered']['#access'] = $render_array['#access'];
    }

    // Only add the raw field items (for use in tokens) if the current user
    // has access to view the field content.
    if ((!isset($items[$count]['rendered']['#access']) || $items[$count]['rendered']['#access']) && !empty($render_array['#items'][$count])) {
      $items[$count]['raw'] = $render_array['#items'][$count];
    }
  }
  return $items;
}