Created
April 30, 2020 09:34
-
-
Save junaidpv/4e121aa04edcda533a8b36acf02ae915 to your computer and use it in GitHub Desktop.
Patch for Drupal module 8 fullcalendar 2.x to allow configure short title in calendar view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/fullcalendar_view.theme.inc b/fullcalendar_view.theme.inc | |
| index fe51c3a..cbc584b 100644 | |
| --- a/fullcalendar_view.theme.inc | |
| +++ b/fullcalendar_view.theme.inc | |
| @@ -244,6 +244,17 @@ function template_preprocess_views_view_fullcalendar(array &$variables) { | |
| else { | |
| $title = t('Invalid event title'); | |
| } | |
| + | |
| + // Event short title. | |
| + if (empty($options['short_title']) || $options['short_title'] == 'title') { | |
| + $short_title = $translated_entity->getTitle(); | |
| + } | |
| + elseif ($current_entity->hasField($options['short_title'])) { | |
| + $short_title = $translated_entity->get($options['short_title'])->value; | |
| + } | |
| + else { | |
| + $short_title = t('Invalid event short title'); | |
| + } | |
| } | |
| else { | |
| // Description for events. For multiple bundle types, | |
| @@ -287,9 +298,21 @@ function template_preprocess_views_view_fullcalendar(array &$variables) { | |
| else { | |
| $title = t('Invalid event title'); | |
| } | |
| + | |
| + // Event short title. | |
| + if (empty($options['short_title']) || $options['short_title'] == 'title') { | |
| + $short_title = $fields['title']->advancedRender($row); | |
| + } | |
| + elseif (!empty($fields[$options['short_title']])) { | |
| + $short_title = $fields[$options['short_title']]->advancedRender($row); | |
| + } | |
| + else { | |
| + $short_title = t('Invalid event short title'); | |
| + } | |
| } | |
| $entry = [ | |
| - 'title' => Xss::filterAdmin($title), | |
| + 'title' => Xss::filterAdmin($short_title), | |
| + 'regular_title' => Xss::filterAdmin($title), | |
| 'description' => $des, | |
| 'id' => $entity_id, | |
| 'url' => $current_entity->toUrl('canonical', ['language' => $language])->toString(), | |
| diff --git a/js/fullcalendar_view.js b/js/fullcalendar_view.js | |
| index 6483df2..8dad064 100644 | |
| --- a/js/fullcalendar_view.js | |
| +++ b/js/fullcalendar_view.js | |
| @@ -37,11 +37,18 @@ | |
| dayClick: dayClickCallback, | |
| eventRender: function(event, $el) { | |
| // Event title with HTML markup. | |
| - $el.find(".fc-title, .fc-list-item-title").html(event.title); | |
| + var calendar_view = $el.closest('.fc-view-container'); | |
| + if (event.source.calendar.view.name == 'month' || event.source.calendar.view.name == 'agendaWeek') { | |
| + $el.find(".fc-title, .fc-list-item-title").html(event.title); | |
| + } | |
| + else { | |
| + $el.find(".fc-title, .fc-list-item-title").html(event.regular_title); | |
| + } | |
| + | |
| // Popup tooltip. | |
| if (event.description) { | |
| if ($el.fullCalendarTooltip !== "undefined") { | |
| - $el.fullCalendarTooltip(event.title, event.description); | |
| + $el.fullCalendarTooltip(event.regular_title, event.description); | |
| } | |
| } | |
| // Recurring event. | |
| diff --git a/src/Plugin/views/style/FullCalendarDisplay.php b/src/Plugin/views/style/FullCalendarDisplay.php | |
| index d66691e..5a30dc0 100644 | |
| --- a/src/Plugin/views/style/FullCalendarDisplay.php | |
| +++ b/src/Plugin/views/style/FullCalendarDisplay.php | |
| @@ -72,6 +72,7 @@ class FullCalendarDisplay extends StylePluginBase { | |
| $options['end'] = ['default' => '']; | |
| $options['des'] = ['default' => '']; | |
| $options['title'] = ['default' => '']; | |
| + $options['short_title'] = ['default' => '']; | |
| $options['use_entity_fields'] = ['default' => TRUE]; | |
| $options['business_start'] = ['default' => '']; | |
| $options['business_end'] = ['default' => '']; | |
| @@ -160,6 +161,15 @@ class FullCalendarDisplay extends StylePluginBase { | |
| '#options' => $field_names, | |
| '#default_value' => (!empty($this->options['title'])) ? $this->options['title'] : '', | |
| ]; | |
| + | |
| + // Field name of short_title. | |
| + $form['short_title'] = [ | |
| + '#title' => $this->t('Short Title Field'), | |
| + '#type' => 'select', | |
| + '#options' => $field_names, | |
| + '#default_value' => (!empty($this->options['short_title'])) ? $this->options['short_title'] : '', | |
| + ]; | |
| + | |
| // Field for description. | |
| $form['des'] = [ | |
| '#title' => $this->t('Description Field'), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment