protected function LanguageFlagFormatter::viewValue in Flags 8
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 LanguageFormatter::viewValue
File
- flags_language/
src/ Plugin/ Field/ FieldFormatter/ LanguageFlagFormatter.php, line 81
Class
- LanguageFlagFormatter
- Plugin implementation of the 'language_flag' formatter.
Namespace
Drupal\flags_language\Plugin\Field\FieldFormatterCode
protected function viewValue(FieldItemInterface $item) {
$view = parent::viewValue($item);
// Base formatter uses #plain_text output but we're adding markup,
// se we need to alter that.
$value = $view['#plain_text'];
$format = $this
->getSetting('flag_display');
$attributes = new Attribute(array(
'class' => array(
$format,
),
));
$view = array();
if ('flag-instead' != $format) {
$view['language'] = array(
'#plain_text' => $value,
);
}
$view['flag'] = array(
'#theme' => 'flags',
'#code' => strtolower($item->value),
'#attributes' => $attributes,
'#source' => 'language',
);
$view['#prefix'] = '<div class="field__flags__item">';
$view['#suffix'] = '</div>';
return $view;
}