You are here

public function TextWithTitleTabsVerticalFormatter::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 TextWithTitleTabsVerticalFormatter::viewElements()
TextWithTitleTabsVerticalFormatter::view in src/Plugin/Field/FieldFormatter/TextWithTitleTabsVerticalFormatter.php
Overide the view method so we can wrap the result in the accordion markup.

File

src/Plugin/Field/FieldFormatter/TextWithTitleTabsVerticalFormatter.php, line 88

Class

TextWithTitleTabsVerticalFormatter
Plugin implementation of the 'TextWithTitleTabsVerticalFormatter' 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;
}