public function TextWithTitleTabsFormatter::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 TextWithTitleTabsFormatter::viewElements()
- TextWithTitleTabsFormatter::view in src/
Plugin/ Field/ FieldFormatter/ TextWithTitleTabsFormatter.php - Overide the view method so we can wrap the result in the accordion markup.
File
- src/
Plugin/ Field/ FieldFormatter/ TextWithTitleTabsFormatter.php, line 48
Class
- TextWithTitleTabsFormatter
- Plugin implementation of the 'TextWithTitleTabsFormatter' formatter.
Namespace
Drupal\text_with_title\Plugin\Field\FieldFormatterCode
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;
}