public function LanguageCombinationDefaultFormatter::viewElements

File

translators/tmgmt_local/skills/src/Plugin/Field/FieldFormatter/LanguageCombinationDefaultFormatter.php, line 26

Class

LanguageCombinationDefaultFormatter
Plugin implementation of the 'tmgmt_language_combination_default' formatter.

Namespace

Drupal\tmgmt_language_combination\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  $installed_languages = \Drupal::languageManager()
    ->getLanguages();
  foreach ($items as $delta => $item) {
    $from = $installed_languages[$item->language_from]
      ->getName();
    $to = $installed_languages[$item->language_to]
      ->getName();
    $elements[$delta]['#markup'] = t('From @from to @to', [
      '@from' => $from,
      '@to' => $to,
    ]);
  }
  return $elements;
}