You are here

public function UnformattedList::viewElements in Double Field 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldFormatter/UnformattedList.php \Drupal\double_field\Plugin\Field\FieldFormatter\UnformattedList::viewElements()

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

File

src/Plugin/Field/FieldFormatter/UnformattedList.php, line 21

Class

UnformattedList
Plugin implementations for 'double_field' formatter.

Namespace

Drupal\double_field\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) : array {
  $element = [];
  $element['#attributes']['class'][] = 'double-field-unformatted-list';
  $settings = $this
    ->getSettings();
  $field_name = $items
    ->getName();
  foreach ($items as $delta => $item) {
    if ($settings['inline']) {
      if (!isset($item->_attributes)) {
        $item->_attributes = [];
      }
      $item->_attributes += [
        'class' => [
          'container-inline',
        ],
      ];
    }
    $element[$delta] = [
      '#theme' => 'double_field_item',
      '#settings' => $settings,
      '#field_settings' => $this
        ->getFieldSettings(),
      '#field_name' => $field_name,
      '#item' => $item,
    ];
  }
  return $element;
}