function SimpleTextFormatter::viewElements
File
-
modules/field_example/src/Plugin/Field/FieldFormatter/SimpleTextFormatter.php, line 25
Class
- SimpleTextFormatter
- Plugin implementation of the 'field_example_simple_text' formatter.
Namespace
Drupal\field_example\Plugin\Field\FieldFormatter
Code
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#attributes' => [
'style' => 'color: ' . $item->value,
],
'#value' => $this->t('The color code in this field is @code', [
'@code' => $item->value,
]),
];
}
return $elements;
}