You are here

public function TextWithTitleTabsHorizontalFormatter::viewElements in Text with Title Field 8

Define how the field type is displayed.

Inside this method we can customize how the field is displayed inside pages.

Overrides FormatterInterface::viewElements

1 call to TextWithTitleTabsHorizontalFormatter::viewElements()
TextWithTitleTabsHorizontalFormatter::view in src/Plugin/Field/FieldFormatter/TextWithTitleTabsHorizontalFormatter.php
Overide the view method so we can wrap the result in the accordion markup.

File

src/Plugin/Field/FieldFormatter/TextWithTitleTabsHorizontalFormatter.php, line 48

Class

TextWithTitleTabsHorizontalFormatter
Implementation of the 'TextWithTitleTabsHorizontalFormatter' formatter.

Namespace

Drupal\text_with_title\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  $id = Html::getUniqueId('bootstrap_tabs');
  foreach ($items as $delta => $item) {
    $elements[$delta] = [
      'title' => [
        '#plain_text' => $item->title,
      ],
      'active' => $delta == 0 ? TRUE : FALSE,
      'id' => $id . '--' . $delta,
      'text' => [
        '#type' => 'processed_text',
        '#text' => $item->text['value'],
        '#format' => $item->text['format'],
        '#langcode' => $langcode,
      ],
    ];
  }
  return $elements;
}