public function ViewfieldFormatterDefault::view in Viewfield 8.3
Builds a renderable array for a fully themed field.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: (optional) The language that should be used to render the field. Defaults to the current content language.
Return value
array A renderable array for a themed field with its label and all its values.
Overrides FormatterBase::view
File
- src/
Plugin/ Field/ FieldFormatter/ ViewfieldFormatterDefault.php, line 94
Class
- ViewfieldFormatterDefault
- Viewfield Default Formatter plugin definition.
Namespace
Drupal\viewfield\Plugin\Field\FieldFormatterCode
public function view(FieldItemListInterface $items, $langcode = NULL) {
$elements = parent::view($items, $langcode);
if (isset($elements['#items'])) {
$elements['#theme'] = 'viewfield';
$elements['#entity'] = $items
->getEntity();
$elements['#entity_type'] = $items
->getEntity()
->getEntityTypeId();
$elements['#bundle'] = $items
->getEntity()
->bundle();
$elements['#field_name'] = $this->fieldDefinition
->getName();
$elements['#field_type'] = $this->fieldDefinition
->getType();
$elements['#view_mode'] = $this->viewMode;
}
return $elements;
}