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', '3.3.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 jQuery plugin</a> with Drupal.', [
'!fullcalendar-uri' => Url::fromUri('https://github.com/arshaw/fullcalendar'),
]) . '</p>';
return $output;
}
}
function fullcalendar_theme($existing, $type, $theme, $path) {
return [
'fullcalendar_event' => [
'variables' => [
'event' => NULL,
'entity' => NULL,
],
'file' => 'fullcalendar.theme.inc',
],
];
}
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 = [
'fc-event-default',
$entity
->bundle(),
];
if (isset($entity->fullcalendar_date_field)) {
$classes[] = "fc-event-field-{$entity->fullcalendar_date_field}";
}
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_fullcalendar_editable(EntityInterface $entity, $view) {
return \Drupal::service('access_check.fullcalendar.update')
->check($entity);
}
function fullcalendar_field_is_date($field, $include_gcal = FALSE) {
if (!$field instanceof EntityField) {
return FALSE;
}
if ($include_gcal && $field->field == 'gcal') {
return TRUE;
}
$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 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' => 'fullcalendar.js',
'min' => 'fullcalendar.min.js',
];
$config = \Drupal::config('fullcalendar.settings');
return $config
->get('path') . '/' . $fullcalendar_file[$config
->get('compression')];
}