-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullcalendar_solr.module
60 lines (52 loc) · 1.96 KB
/
fullcalendar_solr.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* @file
* FullCalendar Solr Views module help and theme functions.
*/
use Drupal\Component\Utility\Html;
use Drupal\Core\Template\Attribute;
/**
* Implements hook_theme().
*/
function fullcalendar_solr_theme($existing, $type, $theme, $path) {
return [
'views_view_fullcalendar_solr' => [
'template' => 'views-view-fullcalendar-solr',
'variables' => [],
],
];
}
/**
* Prepares variables for the FullCalendar style template.
*
* Default template: views-view-fullcalendar-solr.html.twig.
*
* @param array $vars
* An associative array containing:
* - view: A ViewExecutable object
* - rows: The raw row data
* - options: FullCalendar presentation options.
*/
function template_preprocess_views_view_fullcalendar_solr(array &$vars) {
$view = $vars['view'];
// Load libraries.
$vars['#attached']['library'][] = 'fullcalendar_solr/libraries.fullcalendar';
$vars['#attached']['library'][] = 'fullcalendar_solr/fullcalendar_solr';
$fullcalendar_options = $vars['options']['fullcalendar_options'];
// Pass the event and year data as JSON strings. If drupalSettings
// already has values for these and we pass them as arrays, the
// arrays will be merged instead of replaced (same behaviour as
// merging two Javascript objects).
// @link https://www.drupal.org/node/1911578
$vars['#attached']['drupalSettings']['FullCalendarSolr'][] = [
'options' => $fullcalendar_options,
'headingText' => $vars['options']['heading_text'],
'directToItem' => $vars['options']['direct_to_item'],
'events' => json_encode($vars['rows']['events']),
'years' => json_encode($vars['rows']['years']),
];
// Set unique id and index attributes for the fullcalendar instance.
$id = Html::getId('fullcalendar_solr_' . $view->storage->id() . '_' . $view->current_display);
$key = array_key_last($vars['#attached']['drupalSettings']['FullCalendarSolr']);
$vars['attributes'] = new Attribute(['id' => $id, 'fc-solr-index' => $key]);
}