public function FullCalendarOpenStateEventFormatter::format in Booking and Availability Management Tools for Drupal 8
Same name and namespace in other branches
- 7 modules/bat_fullcalendar/src/FullCalendarOpenStateEventFormatter.php \Drupal\bat_fullcalendar\FullCalendarOpenStateEventFormatter::format()
File
- modules/
bat_fullcalendar/ src/ FullCalendarOpenStateEventFormatter.php, line 103 - Class FullCalendarOpenStateEventFormatter
Class
Namespace
Drupal\bat_fullcalendarCode
public function format(EventInterface $event) {
$config = $this->configFactory
->get('bat_fullcalendar.settings');
$editable = FALSE;
// Load the target entity from Drupal.
$target_entity = $this->entityTypeManager
->getStorage($this->eventType
->getTargetEntityType())
->load($event
->getUnitId());
// Get the target entity default value.
$default_value = $target_entity
->getEventDefaultValue($this->eventType
->id());
if ($event
->getValue()) {
$bat_event = bat_event_load($event
->getValue());
// Change the default value to the one that the event actually stores in the entity.
$default_value = $bat_event
->getEventValue();
if (bat_event_access($bat_event, 'update', $this->currentUser)
->isAllowed()) {
$editable = TRUE;
}
}
$formatted_event = [
'start' => $event
->startYear() . '-' . $event
->startMonth('m') . '-' . $event
->startDay('d') . 'T' . $event
->startHour('H') . ':' . $event
->startMinute() . ':00',
'end' => $event
->endYear() . '-' . $event
->endMonth('m') . '-' . $event
->endDay('d') . 'T' . $event
->endHour('H') . ':' . $event
->endMinute() . ':00',
'title' => $target_entity
->formatEventValue($this->eventType
->id(), $default_value),
'blocking' => 0,
'fixed' => 0,
'editable' => $editable,
];
if ($event
->getValue() == 0) {
$formatted_event['color'] = $config
->get('bat_open_state_default_zero_color');
}
else {
$formatted_event['color'] = $config
->get('bat_open_state_default_color');
}
if ($this->background) {
$formatted_event['rendering'] = 'background';
}
$formatted_event['type'] = $this->eventType
->id();
// Allow other modules to alter the event data.
$this->moduleHandler
->alter('bat_fullcalendar_formatted_event', $formatted_event);
return $formatted_event;
}