You are here

public function TextWithTitleTabsFormatter::view in Text with Title Field 8

Overide the view method so we can wrap the result in the accordion markup.

Overrides FormatterBase::view

File

src/Plugin/Field/FieldFormatter/TextWithTitleTabsFormatter.php, line 26

Class

TextWithTitleTabsFormatter
Plugin implementation of the 'TextWithTitleTabsFormatter' formatter.

Namespace

Drupal\text_with_title\Plugin\Field\FieldFormatter

Code

public function view(FieldItemListInterface $items, $langcode = NULL) {

  // Default the language to the current content language.
  if (empty($langcode)) {
    $langcode = \Drupal::languageManager()
      ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
      ->getId();
  }
  $elements = $this
    ->viewElements($items, $langcode);
  $build = [
    '#theme' => 'text_with_title_tabs',
    '#tabs' => $elements,
  ];
  return $build;
}