function SimpleTextFormatter::viewElements
Same name in this branch
- 3.x modules/field_example/src/Plugin/Field/FieldFormatter/SimpleTextFormatter.php \Drupal\field_example\Plugin\Field\FieldFormatter\SimpleTextFormatter::viewElements()
Same name in other branches
- 8.x-1.x field_permission_example/src/Plugin/Field/FieldFormatter/SimpleTextFormatter.php \Drupal\field_permission_example\Plugin\Field\FieldFormatter\SimpleTextFormatter::viewElements()
- 8.x-1.x field_example/src/Plugin/Field/FieldFormatter/SimpleTextFormatter.php \Drupal\field_example\Plugin\Field\FieldFormatter\SimpleTextFormatter::viewElements()
- 4.0.x modules/field_permission_example/src/Plugin/Field/FieldFormatter/SimpleTextFormatter.php \Drupal\field_permission_example\Plugin\Field\FieldFormatter\SimpleTextFormatter::viewElements()
- 4.0.x modules/field_example/src/Plugin/Field/FieldFormatter/SimpleTextFormatter.php \Drupal\field_example\Plugin\Field\FieldFormatter\SimpleTextFormatter::viewElements()
Overrides FormatterInterface::viewElements
File
-
modules/
field_permission_example/ src/ Plugin/ Field/ FieldFormatter/ SimpleTextFormatter.php, line 25
Class
- SimpleTextFormatter
- Plugin implementation of our "sticky-note" formatter.
Namespace
Drupal\field_permission_example\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
// We wrap the fieldnote content up in a div tag.
'#type' => 'html_tag',
'#tag' => 'div',
// This text is auto-XSS escaped. See docs for the html_tag element.
'#value' => $item->value,
// Let's give the note a nice sticky-note CSS appearance.
'#attributes' => [
'class' => 'stickynote',
],
// ..And this is the CSS for the stickynote.
'#attached' => [
'library' => [
'field_permission_example/fieldnote_sticky',
],
],
];
}
return $elements;
}