Allow other modules to "hook" the JS init and add functionality

Created on 1 August 2023, over 1 year ago
Updated 16 August 2023, over 1 year ago

Problem/Motivation

Currently, there is no way to add custom buttons or set callbacks prior to Fullcalendar render.

Steps to reproduce

  1. Go to the Views display settings, open the "display" section
  2. Add custom buttons as normally done for prev/next buttons.

Proposed resolution

Add an observer pattern to allow other modules and themes to override the calendar options before the calendar gets rendered.

  const calendarObj = drupalSettings.calendar[viewIndex];
  // Notify Observer here.
  calendarObj.render();
Feature request
Status

Closed: won't fix

Version

5.1

Component

Code

Created by

🇧🇷Brazil andre.bonon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @andre.bonon
  • Status changed to Closed: won't fix over 1 year ago
  • 🇦🇺Australia mingsong 🇦🇺

    Thanks for raising this idea.
    As this module has been put into bug fixing only mode, it won't deliver any new feature.

    You can try Fullcalendar Block module instead. https://www.drupal.org/project/fullcalendar_block

  • @andrebonon opened merge request.
  • 🇧🇷Brazil andre.bonon

    Hey, I'm attaching the code that helped me to hook it in case others need something similar.

    Additionally, the code below shows how to use the Observer pattern:

      // Alter the Fullcalendar Options before rendering the calendar.
      const fullcalendarViewObserver = {
        update: (calendarOptions) => {
          // Add custom buttons.
          calendarOptions.customButtons = {
            previousMonth: {
              icon: "chevron-left",
              text: "Prev",
              click() {
                // Get some stuff done when users click on Prev button. 
              },
            },
            nextMonth: {
              icon: "chevron-right",
              text: "Next",
              click() {
                // Get some stuff done when users click on Next button. 
              },
            },
          };
    
          return calendarOptions;
        },
      };
    
      // Add a custom observer to Fullcalendar view Subject.
      Drupal.FullcalendarViewSubject.addObserver(fullcalendarViewObserver);
    
Production build 0.71.5 2024