public function LanguageCombinationDefaultFormatter::viewElements in Translation Management Tool 8
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
Overrides FormatterInterface::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\FieldFormatterCode
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;
}