public function TermLevelFormatter::viewElements in Term Level Field 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 EntityReferenceLabelFormatter::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ TermLevelFormatter.php, line 25
Class
- TermLevelFormatter
- Plugin for Term level formatter.
Namespace
Drupal\term_level\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = parent::viewElements($items, $langcode);
$values = $items
->getValue();
$field_settings = $this
->getFieldSettings();
$levels = TermLevelItem::extractLevels($field_settings['levels']);
foreach ($elements as $delta => $entity) {
$level = $values[$delta]['level'];
$elements[$delta]['level'] = [
'#markup' => ' : ' . $levels[$level],
];
}
return $elements;
}