public function BatCalendarRawFormatter::viewElements in Booking and Availability Management Tools for Drupal 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
- modules/
bat_calendar_reference/ src/ Plugin/ Field/ FieldFormatter/ BatCalendarRawFormatter.php, line 28 - Contains \Drupal\bat_calendar_reference\Plugin\Field\FieldFormatter\BatCalendarRawFormatter.
Class
- BatCalendarRawFormatter
- Plugin annotation @FieldFormatter( id = "bat_calendar_reference_raw_formatter", label = @Translation("Raw"), field_types = { "bat_calendar_unit_reference", "bat_calendar_unit_type_reference", } )
Namespace
Drupal\bat_calendar_reference\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$field_type = $this->fieldDefinition
->getFieldStorageDefinition()
->getType();
if ($field_type == 'bat_calendar_unit_type_reference') {
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#markup' => t('Unit type id: @unit_type_id - Event type id: @event_type_id', [
'@unit_type_id' => $item->unit_type_id,
'@event_type_id' => $item->event_type_id,
]),
];
}
}
elseif ($field_type == 'bat_calendar_unit_reference') {
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#markup' => t('Unit id: @unit_id - Event type id: @event_type_id', [
'@unit_id' => $item->unit_id,
'@event_type_id' => $item->event_type_id,
]),
];
}
}
return $elements;
}