public function EditorNoteTableFormatter::viewElements in Editor Notes 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 FormatterInterface::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ EditorNoteTableFormatter.php, line 78
Class
- EditorNoteTableFormatter
- Plugin implementation of the 'Editor Note' formatter.
Namespace
Drupal\editor_note\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$entity = $items
->getEntity();
$notes = $this->editorNoteHelper
->getNotesByEntityAndField($entity
->id(), $this->fieldDefinition
->getName());
$field = $this->fieldDefinition;
$table = $this->editorNoteHelper
->generateTable($field, $notes, FALSE);
if (!isset($table['notes_table'])) {
return [];
}
$data = $table['notes_table'];
$data['#prefix'] = $table['#prefix'];
$data['#suffix'] = $table['#suffix'];
return $data;
}