View source
<?php
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\field\EntityField;
define('FULLCALENDAR_MIN_PLUGIN_VERSION', '4.0.0');
function fullcalendar_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.fullcalendar':
$output = '';
$output .= '<h3>' . t('Fullcalendar') . '</h3>';
$output .= '<p>' . t('The Fullcalendar module is an integration of the <a href=":fullcalendar-uri">Adam Shaw\'s FullCalendar Javascript calendar</a> with Drupal.', [
':fullcalendar-uri' => Url::fromUri('https://fullcalendar.io')
->toString(),
]) . '</p>';
return $output;
}
}
function fullcalendar_theme($existing, $type, $theme, $path) {
return [
'views_view__fullcalendar' => [
'template' => 'views-view--fullcalendar',
'base hook' => 'view',
],
];
}
function fullcalendar_permission() {
return [
'update any fullcalendar event' => [
'title' => t('Update any FullCalendar event'),
'description' => t('Allow user to edit events, ignoring other permissions.'),
],
];
}
function fullcalendar_fullcalendar_classes(EntityInterface $entity) {
$classes = [];
if (\Drupal::moduleHandler()
->moduleExists('colors')) {
$classes = array_merge($classes, \Drupal::service('module_handler')
->invokeAll('colors_classes', [
$entity,
]));
}
$classes = array_merge($classes, [
'fc-event-default',
$entity
->bundle(),
]);
return $classes;
}
function fullcalendar_form_views_ui_edit_display_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$style = $form_state
->get('view')
->get('executable')->display_handler
->getOption('style');
if ($style['type'] != 'fullcalendar' || empty($form['options']['query']['options']['distinct'])) {
return;
}
$distinct =& $form['options']['query']['options']['distinct'];
if (!isset($distinct['#description'])) {
$distinct['#description'] = '';
}
else {
$distinct['#description'] .= '<br>';
}
$distinct['#disabled'] = TRUE;
$distinct['#description'] .= '<strong>' . t('FullCalendar requires that the query be distinct.') . '</strong>';
}
function fullcalendar_field_is_date(EntityField $field) {
if (!$field instanceof EntityField) {
return FALSE;
}
$entity_type = $field->definition['entity_type'];
if (empty($entity_type)) {
return FALSE;
}
$field_manager = \Drupal::getContainer()
->get('entity_field.manager');
$field_storages = $field_manager
->getFieldStorageDefinitions($entity_type);
if (isset($field_storages[$field->definition['field_name']])) {
$field_storage = $field_storages[$field->definition['field_name']];
return in_array($field_storage
->getType(), [
'datetime',
'daterange',
'date_recur',
]);
}
return FALSE;
}
function fullcalendar_get_version($fullcalendar_path = NULL) {
$version =& drupal_static(__FUNCTION__);
if (empty($version)) {
$version = 0;
$pattern = '#FullCalendar[A-Za-z\\s]+v([0-9\\.a-z]+)#';
if (!$fullcalendar_path) {
$fullcalendar_path = fullcalendar_get_js_path();
}
$fullcalendar_plugin = file_get_contents($fullcalendar_path, NULL, NULL, 0, 40);
if (preg_match($pattern, $fullcalendar_plugin, $matches)) {
$version = $matches[1];
}
}
return $version;
}
function fullcalendar_get_js_path() {
$fullcalendar_file = [
'none' => 'main.js',
'min' => 'main.js',
];
$config = \Drupal::config('fullcalendar.settings');
return $config
->get('path') . '/' . $fullcalendar_file[$config
->get('compression')];
}
function fullcalendar_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
if ($hook === 'views_view') {
$suggestions[] = "views_view__" . $variables['view']->style_plugin
->getPluginId();
}
}
function fullcalendar_page_attachments(array &$attachments) {
if (\Drupal::moduleHandler()
->moduleExists('colors')) {
$css = colors_create_css('fullcalendar');
$attachments['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'style',
'#value' => $css,
'#weight' => 1000,
],
'fullcalendar-inline-css',
];
}
}
function fullcalendar_colors_rebuild() {
return TRUE;
}
function fullcalendar_colors_build_selector($class) {
$selector = [
".{$class}",
".{$class} .fc-event-default",
".{$class} .fc-event-default .fc-event-skin",
".{$class} .fc-event-default .fc-event-time",
".{$class} .fc-event-default a",
];
return implode(', ', $selector);
}
function fullcalendar_fullcalendar_palette($entity) {
$palette = [];
if (\Drupal::moduleHandler()
->moduleExists('colors')) {
$palettes = \Drupal::service('module_handler')
->invokeAll('colors_palette', [
$entity,
]);
if (!empty($palettes)) {
$palettes = reset($palettes);
$palette['backgroundColor'] = $palettes['bg'];
$palette['borderColor'] = $palettes['borders'];
$palette['textColor'] = $palettes['text'];
}
}
return $palette;
}