Skip to content

Instantly share code, notes, and snippets.

@junaidpv
Last active December 8, 2023 17:35
Show Gist options
  • Save junaidpv/75ca7da59475959d523d913bd7f63775 to your computer and use it in GitHub Desktop.
Save junaidpv/75ca7da59475959d523d913bd7f63775 to your computer and use it in GitHub Desktop.
To allow to set short title on calender events. Now rewrote to work witih dynamic loading of evetns. Updated for 5.1.13
diff --git a/js/fullcalendar_view.js b/js/fullcalendar_view.js
index b6a6a84..977649b 100644
--- a/js/fullcalendar_view.js
+++ b/js/fullcalendar_view.js
@@ -54,7 +54,7 @@
// Show Tooltip on Mousehover
let thisEvent = info.event;
let des = thisEvent.extendedProps.des;
- let title = thisEvent.title;
+ let title = thisEvent.extendedProps.regular_title;
if(des.length > 0) {
$(info.el).fullCalendarTooltip(title, des);
}
@@ -341,6 +341,16 @@
}
// Language select element.
var localeSelectorEl = document.getElementById('locale-selector-' + viewIndex);
+
+ let urlParams = new URLSearchParams(window.location.search);
+ let fcview = urlParams.get('fcview');
+ if (fcview) {
+ // for v4
+ calendarOptions.defaultView = fcview;
+ // for v5
+ calendarOptions.initialView = fcview;
+ }
+
// Allow passing a default date via query string.
const params = (new URL(document.location)).searchParams;
const initialDate = params.get('initialDate')
diff --git a/src/FullcalendarViewPreprocess.php b/src/FullcalendarViewPreprocess.php
index f0b35ac..2942642 100644
--- a/src/FullcalendarViewPreprocess.php
+++ b/src/FullcalendarViewPreprocess.php
@@ -411,6 +411,18 @@ class FullcalendarViewPreprocess
} 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');
+ }
+
$link_url = strstr($title, 'href="');
if ($link_url) {
$link_url = substr($link_url, 6);
@@ -423,7 +435,8 @@ class FullcalendarViewPreprocess
if (isset($start_field_option['type']) && $start_field_option["type"] == "smartdate_default") {
$idkey = $row->index . '-0';
$entry = [
- 'title' => Xss::filter($title, $title_allowed_tags),
+ 'title' => Xss::filter($short_title, $title_allowed_tags),
+ 'regular_title' => Xss::filter($title, $title_allowed_tags),
'id' => $idkey,
'eid' => $entity_id,
'url' => $link_url,
@@ -512,7 +525,8 @@ class FullcalendarViewPreprocess
foreach ($start_dates as $i => $start_date) {
$idkey = $row->index . '-' . $i;
$entry = [
- 'title' => Xss::filter($title, $title_allowed_tags),
+ 'title' => Xss::filter($short_title, $title_allowed_tags),
+ 'regular_title' => Xss::filter($title, $title_allowed_tags),
'id' => $idkey,
'eid' => $entity_id,
'url' => $link_url,
diff --git a/src/Plugin/views/style/FullCalendarDisplay.php b/src/Plugin/views/style/FullCalendarDisplay.php
index e0883e7..4bddc2a 100644
--- a/src/Plugin/views/style/FullCalendarDisplay.php
+++ b/src/Plugin/views/style/FullCalendarDisplay.php
@@ -124,6 +124,7 @@ class FullCalendarDisplay extends StylePluginBase {
$options['start'] = ['default' => ''];
$options['end'] = ['default' => ''];
$options['title'] = ['default' => ''];
+ $options['short_title'] = ['default' => ''];
$options['date_filter'] = ['default' => ''];
$options['duration'] = ['default' => ''];
$options['rrule'] = ['default' => ''];
@@ -231,7 +232,13 @@ class FullCalendarDisplay extends StylePluginBase {
'#empty_value' => '',
'#default_value' => (!empty($this->options['date_filter'])) ? $this->options['date_filter'] : '',
];
-
+ // 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'] : '',
+ ];
// Display settings.
$form['display'] = [
'#type' => 'details',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment