class FullCalendarFixedStateEventFormatter in Booking and Availability Management Tools for Drupal 8
Same name and namespace in other branches
- 7 modules/bat_fullcalendar/src/FullCalendarFixedStateEventFormatter.php \Drupal\bat_fullcalendar\FullCalendarFixedStateEventFormatter
Hierarchy
- class \Drupal\bat_fullcalendar\FullCalendarFixedStateEventFormatter extends \Roomify\Bat\EventFormatter\AbstractEventFormatter
Expanded class hierarchy of FullCalendarFixedStateEventFormatter
1 string reference to 'FullCalendarFixedStateEventFormatter'
- bat_fullcalendar.services.yml in modules/
bat_fullcalendar/ bat_fullcalendar.services.yml - modules/bat_fullcalendar/bat_fullcalendar.services.yml
1 service uses FullCalendarFixedStateEventFormatter
File
- modules/
bat_fullcalendar/ src/ FullCalendarFixedStateEventFormatter.php, line 20 - Class FullCalendarFixedStateEventFormatter
Namespace
Drupal\bat_fullcalendarView source
class FullCalendarFixedStateEventFormatter extends AbstractEventFormatter {
/**
* The event type.
*
* @var \Drupal\bat_event\EventTypeInterface
*/
protected $eventType;
/**
* Print as background event.
*
* @var bool
*/
protected $background;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* @param \Drupal\Core\Session\AccountInterface $current_user
* Current user.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(AccountInterface $current_user, ModuleHandlerInterface $module_handler) {
$this->background = TRUE;
$this->currentUser = $current_user;
$this->moduleHandler = $module_handler;
}
/**
* @param \Drupal\bat_event\EventTypeInterface $event_type
* The event type.
*/
public function setEventType(EventTypeInterface $event_type) {
$this->eventType = $event_type;
}
/**
* @param bool $background
* The event type.
*/
public function setBackground($background) {
$this->background = $background;
}
/**
* {@inheritdoc}
*/
public function format(EventInterface $event) {
$editable = FALSE;
// Load the unit entity from Drupal.
$bat_unit = bat_unit_load($event
->getUnitId());
// Get the unit entity default value.
$default_value = $bat_unit
->getEventDefaultValue($this->eventType
->id());
// Get the default state info which will provide the default value for formatting.
$state_info = bat_event_load_state($default_value);
$calendar_label = $state_info
->getCalendarLabel();
// However if the event is in the database, then load the actual event and get its value.
if ($event
->getValue()) {
// Load the event from the database to get the actual state and load that info.
if ($bat_event = bat_event_load($event
->getValue())) {
$state_info = bat_event_load_state($bat_event
->getEventValue());
$calendar_label = $state_info
->getCalendarLabel();
if ($event_label = $bat_event
->getEventLabel()) {
$calendar_label = $event_label;
}
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' => $calendar_label,
'color' => $state_info->color->value,
'blocking' => 1,
'fixed' => 1,
'editable' => $editable,
];
// Render non blocking events in the background.
if ($state_info
->getBlocking() == 0) {
if ($this->background) {
$formatted_event['rendering'] = 'background';
}
$formatted_event['blocking'] = 0;
}
$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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FullCalendarFixedStateEventFormatter:: |
protected | property | Print as background event. | |
FullCalendarFixedStateEventFormatter:: |
protected | property | The current user. | |
FullCalendarFixedStateEventFormatter:: |
protected | property | The event type. | |
FullCalendarFixedStateEventFormatter:: |
protected | property | The module handler. | |
FullCalendarFixedStateEventFormatter:: |
public | function | ||
FullCalendarFixedStateEventFormatter:: |
public | function | ||
FullCalendarFixedStateEventFormatter:: |
public | function | ||
FullCalendarFixedStateEventFormatter:: |
public | function |