1 field.block.inc FieldBlock::getContent()

Sets block content on block view.

Overrides Block::getContent

File

core/modules/field/field.block.inc, line 64

Class

FieldBlock
FieldBlock extends Block

Code

function getContent() {
  $settings = $this->settings;

  // Get a shortcut to the entity.
  list($entity_type, $field_name) = explode('-', $this->childDelta);
  $entity = $this->contexts[$entity_type]->data;

  // Load the entity type's information for this field.
  $field = field_info_instance($entity_type, $field_name, $entity->bundle());

  // Do not render if the entity type does not have this field.
  if (empty($field)) {
    return NULL;
  }
  $language = field_language($entity_type, $entity, $field_name);

  $field_settings = array(
    'type' => $settings['formatter'],
    'settings' => $settings['formatter_settings'],
    'label' => $settings['label'],
  );

  $all_values = field_get_items($entity_type, $entity, $field_name, $language);
  if (!is_array($all_values)) {
    // Do not render if the field is empty.
    return NULL;
  }
  // Reverse values.
  if ($settings['delta_reversed']) {
    $all_values = array_reverse($all_values, TRUE);
  }

  if (isset($settings['delta_limit'])) {
    $offset = intval($settings['delta_offset']);
    $limit = !empty($settings['delta_limit']) ? $settings['delta_limit'] : NULL;
    $all_values = array_slice($all_values, $offset, $limit, TRUE);
  }

  $clone = clone $entity;
  $clone->{$field_name}[$language] = $all_values;
  $field_output = field_view_field($entity_type, $clone, $field_name, $field_settings, $language);

  return $field_output;
}