private function FullCalendar::prepareEvent in FullCalendar 8.2
Same name and namespace in other branches
- 8.5 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::prepareEvent()
- 8 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::prepareEvent()
- 8.3 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::prepareEvent()
- 8.4 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::prepareEvent()
Helper method to prepare an event.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: Event entity.
$fields:
int $delta: Field delta.
Return value
array
Throws
\Exception
1 call to FullCalendar::prepareEvent()
- FullCalendar::prepareEvents in src/
Plugin/ views/ style/ FullCalendar.php - Prepare events for calendar.
File
- src/
Plugin/ views/ style/ FullCalendar.php, line 425
Class
- FullCalendar
- Plugin annotation @ViewsStyle( id = "fullcalendar", title = @Translation("FullCalendar"), help = @Translation("Displays items on a calendar."), theme = "views_view--fullcalendar", display_types = {"normal"} )
Namespace
Drupal\fullcalendar\Plugin\views\styleCode
private function prepareEvent($entity, $fields, $delta) {
$classes = $this->moduleHandler
->invokeAll('fullcalendar_classes', [
$entity,
]);
$this->moduleHandler
->alter('fullcalendar_classes', $classes, $entity);
$classes = array_map([
'\\Drupal\\Component\\Utility\\Html',
'getClass',
], $classes);
$class = count($classes) ? implode(' ', array_unique($classes)) : '';
$palette = $this->moduleHandler
->invokeAll('fullcalendar_palette', [
$entity,
]);
$this->moduleHandler
->alter('fullcalendar_palette', $palette, $entity);
// Start/end dates.
$event_start_end = $this
->getEventStartEndDates($fields);
$event_start = $event_start_end['start'];
$event_end = $event_start_end['end'];
$all_day = $this
->isAllDayEvent($event_start_end);
$request_time = \Drupal::time()
->getRequestTime();
$current_time = new DateTime();
$current_time
->setTimestamp($request_time)
->format(DateTime::ATOM);
// Add a class if the event was in the past or is in the future, based
// on the end time. We can't do this in hook_fullcalendar_classes()
// because the date hasn't been processed yet.
if ($all_day && $event_start < $current_time || !$all_day && $event_end < $current_time) {
$time_class = 'fc-event-past';
}
elseif ($event_start > $current_time) {
$time_class = 'fc-event-future';
}
else {
$time_class = 'fc-event-now';
}
$editable = !empty($settings['fullcalendar']['editable']) ? $entity
->access('update', NULL, TRUE)
->isAllowed() : FALSE;
return [
'id' => $entity
->id(),
'groupId' => $entity
->getEntityTypeId(),
'allDay' => $all_day,
'start' => $event_start,
'end' => $event_end,
'editable' => $editable,
'className' => $class . ' ' . $time_class,
'title' => strip_tags(htmlspecialchars_decode($entity
->label(), ENT_QUOTES)),
'url' => $entity
->toUrl('canonical', [
'language' => \Drupal::languageManager()
->getCurrentLanguage(),
])
->toString(),
'backgroundColor' => !empty($palette['backgroundColor']) ? $palette['backgroundColor'] : '',
'borderColor' => !empty($palette['borderColor']) ? $palette['borderColor'] : '',
'textColor' => !empty($palette['textColor']) ? $palette['textColor'] : '',
];
}