public function RadioactivityEmitter::viewElements in Radioactivity 4.0.x
Same name and namespace in other branches
- 8.3 src/Plugin/Field/FieldFormatter/RadioactivityEmitter.php \Drupal\radioactivity\Plugin\Field\FieldFormatter\RadioactivityEmitter::viewElements()
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
- src/
Plugin/ Field/ FieldFormatter/ RadioactivityEmitter.php, line 83
Class
- RadioactivityEmitter
- Plugin implementation of the 'radioactivity_emitter' formatter.
Namespace
Drupal\radioactivity\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$shouldEmit = $this
->shouldEmit($items);
foreach ($items as $delta => $item) {
if ($shouldEmit) {
$incident = Incident::createFromFieldItemsAndFormatter($items, $item, $this);
$key = 'ra_emit_' . radioactivity_unique_emit_id();
$elements[$delta] = [
'#attached' => [
'library' => [
'radioactivity/triggers',
],
'drupalSettings' => [
$key => $incident
->toJson(),
],
],
];
}
switch ($this
->getSetting('display')) {
case 'raw':
$elements[$delta]['#markup'] = $this
->viewValue($item);
break;
}
}
return $elements;
}