Skip to content

Instantly share code, notes, and snippets.

@junaidpv
Last active July 19, 2022 15:42
Show Gist options
  • Save junaidpv/961cf03bc4a5d1d2b02dd13af9766e20 to your computer and use it in GitHub Desktop.
Save junaidpv/961cf03bc4a5d1d2b02dd13af9766e20 to your computer and use it in GitHub Desktop.
Replacement patch https://gist.github.com/junaidpv/4e121aa04edcda533a8b36acf02ae915 . To allow to set short title on calender events.
diff --git a/js/fullcalendar_view.js b/js/fullcalendar_view.js
index 35ad731..500fbfc 100644
--- a/js/fullcalendar_view.js
+++ b/js/fullcalendar_view.js
@@ -35,7 +35,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);
}
@@ -277,6 +277,16 @@
calendarOptions.eventDrop = eventDrop;
// 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;
+ }
+
// Initial the calendar.
if (calendarEl) {
if (drupalSettings.calendar) {
diff --git a/src/FullcalendarViewPreprocess.php b/src/FullcalendarViewPreprocess.php
index bd0964d..43f865f 100644
--- a/src/FullcalendarViewPreprocess.php
+++ b/src/FullcalendarViewPreprocess.php
@@ -183,6 +183,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);
@@ -197,7 +209,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 5354e1b..1428637 100644
--- a/src/Plugin/views/style/FullCalendarDisplay.php
+++ b/src/Plugin/views/style/FullCalendarDisplay.php
@@ -69,6 +69,7 @@ class FullCalendarDisplay extends StylePluginBase {
$options['start'] = ['default' => ''];
$options['end'] = ['default' => ''];
$options['title'] = ['default' => ''];
+ $options['short_title'] = ['default' => ''];
$options['duration'] = ['default' => ''];
$options['rrule'] = ['default' => ''];
$options['bundle_type'] = ['default' => ''];
@@ -160,6 +161,13 @@ 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'] : '',
+ ];
// Display settings.
$form['display'] = [
'#type' => 'details',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment