BatCalendarRawFormatter.php in Booking and Availability Management Tools for Drupal 8
File
modules/bat_calendar_reference/src/Plugin/Field/FieldFormatter/BatCalendarRawFormatter.php
View source
<?php
namespace Drupal\bat_calendar_reference\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
class BatCalendarRawFormatter extends FormatterBase {
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;
}
}
Classes
Name |
Description |
BatCalendarRawFormatter |
Plugin annotation
@FieldFormatter(
id = "bat_calendar_reference_raw_formatter",
label = @Translation("Raw"),
field_types = {
"bat_calendar_unit_reference",
"bat_calendar_unit_type_reference",
}
) |