You are here

UnformattedList.php in Double Field 4.x

Same filename and directory in other branches
  1. 8.3 src/Plugin/Field/FieldFormatter/UnformattedList.php

File

src/Plugin/Field/FieldFormatter/UnformattedList.php
View source
<?php

namespace Drupal\double_field\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;

/**
 * Plugin implementations for 'double_field' formatter.
 *
 * @FieldFormatter(
 *   id = "double_field_unformatted_list",
 *   label = @Translation("Unformatted list"),
 *   field_types = {"double_field"}
 * )
 */
class UnformattedList extends ListBase {

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Classes

Namesort descending Description
UnformattedList Plugin implementations for 'double_field' formatter.