You are here

protected function LanguageFormatter::viewValue in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/LanguageFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\LanguageFormatter::viewValue()

Generate the output appropriate for one field item.

Parameters

\Drupal\Core\Field\FieldItemInterface $item: One field item.

Return value

array The textual output generated as a render array.

Overrides StringFormatter::viewValue

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/LanguageFormatter.php, line 119
Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\LanguageFormatter.

Class

LanguageFormatter
Plugin implementation of the 'language' formatter.

Namespace

Drupal\Core\Field\Plugin\Field\FieldFormatter

Code

protected function viewValue(FieldItemInterface $item) {

  // The 'languages' cache context is not necessary because the language is
  // either displayed in its configured form (loaded directly from config
  // storage by LanguageManager::getLanguages()) or in its native language
  // name. That only depends on formatter settings and no language condition.
  $languages = $this
    ->getSetting('native_language') ? $this->languageManager
    ->getNativeLanguages(LanguageInterface::STATE_ALL) : $this->languageManager
    ->getLanguages(LanguageInterface::STATE_ALL);
  return [
    '#plain_text' => $item->language && isset($languages[$item->language
      ->getId()]) ? $languages[$item->language
      ->getId()]
      ->getName() : '',
  ];
}