Hi Mingsong,
first of all THANK YOU for this wonderful and WORKING calendar module.

What i am thinking of is an option to restrict the hours the calendar shows.
At the moment there is always all 24 hours shown in the calendar.
But if my opening hours are from 8 -18 o´clock there is no need to show 0-7 an 19-24.

Others also thought if that right here :)
https://stackoverflow.com/questions/27688279/full-calendar-business-hours

It would be great if such an Option would be available (maybe even included with
https://www.drupal.org/project/fullcalendar_view/issues/2993009

Best Regards

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torstenzenk created an issue. See original summary.

dww’s picture

This, this would be great. I wonder if I'll find time and a way to get this working. Meanwhile, "+1". ;)

blueblot’s picture

That would be a nice feature.

dww’s picture

Status: Active » Needs review
FileSize
574 bytes

Initial patch to enable this to work at all. ;)

To use it, you'd have to have this in your theme or custom module:

/**
 * Implements hook_preprocess_views_view_fullcalendar()
 */
function example_preprocess_views_view_fullcalendar(array &$variables) {
  $variables['#attached']['drupalSettings']['minTime'] = '07:00:00';
  $variables['#attached']['drupalSettings']['maxTime'] = '22:00:00';
}

Next step would be making it a setting for the Views display handler.

MaxPah’s picture

Hello,

Here is my patch from a project.

Settigns minTime and maxTime are added from views setting no hook needed.

Feel free to comment the form part.

Mingsong’s picture

Thanks Maxime Pahud.

I am currently working on the Drupal 9 version of this module, in which will support external plugin where you can define your own new feature working with this module seamlessly.

MaxPah’s picture

Thanks for the information Mingsong !

I readd my patch here in case of someone on branch 2.x need it.

mvilluendas’s picture

Thank you for the solutions.
Are there any updates to these patches for the 5.x-dev branch?

darklight90’s picture

Hello,
do we have a patch for v 5.1.2 too?
Thanks

darklight90’s picture

I think I solved the problem for the last version of this module:

diff --git a/src/FullcalendarViewPreprocess.php b/src/FullcalendarViewPreprocess.php
index ef51849..7db05ef 100644
--- a/src/FullcalendarViewPreprocess.php
+++ b/src/FullcalendarViewPreprocess.php
@@ -111,6 +111,9 @@ class FullcalendarViewPreprocess {
     $start_field_option['settings']['timezone_override'] : date_default_timezone_get();
     // Set the first day setting.
     $first_day = isset($options['firstDay']) ? intval($options['firstDay']) : 0;
+    // custom mod
+    $minTime = isset($options['minTime']) ? $options['minTime'] : '00:00:00';
+    $maxTime = isset($options['maxTime']) ? $options['maxTime'] : '23:59:59';
     // Left side buttons.
     $left_buttons = Xss::filter($options['left_buttons']);
     // Right side buttons.
@@ -335,6 +338,9 @@ class FullcalendarViewPreprocess {
         ],
         'eventTimeFormat' => $timeFormat,
         'firstDay' => $first_day,
+        // custom mod
+        'minTime' => $minTime,
+        'maxTime' => $maxTime,
         'locale' => $default_lang,
         'events' => $entries,
         'navLinks' => $options['nav_links'] !== 0,
diff --git a/src/Plugin/views/style/FullCalendarDisplay.php b/src/Plugin/views/style/FullCalendarDisplay.php
index d3087ff..48a5279 100644
--- a/src/Plugin/views/style/FullCalendarDisplay.php
+++ b/src/Plugin/views/style/FullCalendarDisplay.php
@@ -228,6 +228,23 @@ class FullCalendarDisplay extends StylePluginBase {
       '#default_value' => (empty($this->options['firstDay'])) ? '0' : $this->options['firstDay'],
       '#title' => $this->t('First Day'),
     ];
+    // custom mod
+    // MinTime
+    $form['minTime'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('minTime'),
+      '#default_value' => !empty($this->options['minTime']) ? $this->options['minTime'] : '00:00:00',
+      '#pattern' => '(([0-1][0-9])|([2][0-3])):([0-5][0-9]):([0-5][0-9])',
+      '#required' => TRUE,
+    ];
+    // MaxTime
+    $form['maxTime'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('maxTime'),
+      '#default_value' => !empty($this->options['maxTime']) ? $this->options['maxTime'] : '23:59:59',
+      '#pattern' => '(([0-1][0-9])|([2][0-3])):([0-5][0-9]):([0-5][0-9])',
+      '#required' => TRUE,
+    ];
     // Nav Links.
     $form['nav_links'] = [
      '#type' => 'checkbox',
mandclu’s picture

I was poking around in the FullCalendar documentation and noticed that the library has support for a businessHours parameter that can be passed in to define what hours show as available in the day view. Not really the same as what has been discussed here, but might be a nice addition, to add visual feedback to this feature.

jon.lund’s picture

#10 works for me. This is exactly what I was looking for. Thank you.

Bès’s picture

Version: 8.x-2.x-dev » 5.x-dev
Assigned: Unassigned » Bès

Preparing patch for 5.x

Bès’s picture

Assigned: Bès » Unassigned

Patch for 5.x can be found in the merge request.

Patch for branch 2.X is in comment #7

I use a datetime form element to have a better widget in the configuration form.

DuneBL’s picture

#14 is working for v5. many thanks

DuneBL’s picture

MR 28 doesn't apply anymore on last v5

diegors made their first commit to this issue’s fork.

diegors’s picture

Rebase done.

Mingsong’s picture

Thanks everyone for working or providing your thought on this issue.

I made some minor changes on the MR.

If I could have anyone to test and confirm the last changes to the MR, that would be very helpful.

I will merge it once it is tested and confirmed.

  • Mingsong committed 89f12853 on 5.x authored by Bès
    Issue #3009683: Restrict hours on calendar (Opening hours)
    
Mingsong’s picture

Status: Needs review » Fixed

Release with 5.1.9.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.