public function ForwardFormFormatter::prepareView in Forward 4.0.x
Same name and namespace in other branches
- 4.x src/Plugin/Field/FieldFormatter/ForwardFormFormatter.php \Drupal\forward\Plugin\Field\FieldFormatter\ForwardFormFormatter::prepareView()
Allows formatters to load information for field values being displayed.
This should be used when a formatter needs to load additional information from the database in order to render a field, for example a reference field that displays properties of the referenced entities such as name or type.
This method operates on multiple entities. The $entities_items parameter is an array keyed by entity ID. For performance reasons, information for all involved entities should be loaded in a single query where possible.
Changes or additions to field values are done by directly altering the items.
Parameters
\Drupal\Core\Field\FieldItemListInterface[] $entities_items: An array with the field values from the multiple entities being rendered.
Overrides FormatterBase::prepareView
File
- src/
Plugin/ Field/ FieldFormatter/ ForwardFormFormatter.php, line 93
Class
- ForwardFormFormatter
- Plugin implementation of the Forward Form formatter.
Namespace
Drupal\forward\Plugin\Field\FieldFormatterCode
public function prepareView(array $entities_items) {
foreach ($entities_items as $item) {
// If the display field is empty, it means the edit widget
// has never been used for this entity. In this case,
// default to display the link. The user can then edit
// the entity and hide the link if needed.
if ($item
->isEmpty()) {
$display = TRUE;
$item
->appendItem($display);
}
}
}