Problem/Motivation
With a recent release, the Calendar module is now Drupal 9 compatible. Ideally Smart Date events could be displayed using the Calendar module.
Proposed resolution
Explore ways Smart Date could support integration with the Calendar module.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | smart_date-support_calendar_module-3177760-13.patch | 2.26 KB | veronicaseveryn |
| #8 | views.view_.test_calendar.yml | 6.56 KB | grahamc |
| #5 | 3177760-5.smart_date.Support-Calendar-module.patch | 2.26 KB | grahamc |
Comments
Comment #2
ruslan piskarovSubscribing.
For some projects, we can't use the Full Calendar View module and support for Calendar will be ideal.
Comment #3
sseto commentedHey Mandclu. Was wondering if there's any progress with this? Thanks!
Comment #4
mandclu commentedI'll be honest, I haven't had the bandwidth to try this out in a while. If anyone has the capacity and report back on specific changes needed to make this work, that would be a big help.
That said, if anyone can't use Fallcalendar View because of the way it loads all events, you could also look at the newer Fullcalendar Block which apparently asynchronously loads events for each month as a user clicks around. I don't know that it supports Smart Date yet, but if I had to guess, I would think that would actually be easier to get working, since it's the same maintainer as Fullcalendar View.
Comment #5
grahamcI have this up and running...
Main thing required is providing granular views argument handlers Calendar can use to filter by specific day/week/month/year. Attached patch reproduces the ones which already exist for core date fields.
There's also a tiny issue on the calendar side - it's unable to detect the correct data format in one specific place. I'll add that patch to #3177761-6: Support for Smart Date, other contrib modules
Comment #6
mandclu commentedWould love to get this into the 3.6.x branch, will try to review in the coming days.
Comment #7
mandclu commented@grahamC Thanks so much for your work on this! Just tried to test this with a fresh site install using the Smart Date Starter Kit and Calendar, but was unable to create a new view with a Calendar display. I got this error:
\Drupal\calendar\Plugin\views\style\CalendarStyle: A calendar date argument is required when using the calendar style, to add a date argument in a view, please go to Advanced > Contextual Filters on the views configuration panel.Is it necessary to create a view, manually add a contextual filter, and then switch to the Calendar display?
I also creating a view using the "Add view from template" approach that is recommended with Calendar, but didn't see an option in there that looked like it would create a Calendar of Event nodes using the When field.
Could you provide steps to follow to test your work?
Comment #8
grahamcYes, that's basically it! Sample config for a month view (using Smart Date Starter Kit) attached - I used the following steps:
- Add contextual filter on one of the new granularity fields (e.g. "node.field_when (year_month)" for month calendar )
- Set "provide default value" to Calendar: Current Date (also set the validation criteria to "Calendar Date Format" to get a nice page title)
- Set style to Calendar and row plugin to Calendar Entities
- Set pager to Calendar
- Add Calendar header to display title
I suspect it'd be easy enough to hook into the views template thing and provide a preset for day/week/month/year as calendar does for core fields... or maybe that part is calendar's responsibility again? hmm
Comment #9
mandclu commentedA couple of additional thoughts here:
The 3.6.x branch now includes granularity for the views filter (via #3055994: Views Date Filter Datetime Granularity Option), though not all the options introduced in the patch here are available. Maybe the patch could be refactored to extend that?
Having the support available to configure your own calendar view is important, but I think to have parity with how the Calendar works with other kinds of date fields, we should also implement a view template. That could be a child issue, I suppose.
Comment #10
grahamcThere's a major issue not addressed by the current patch, leading to duplicated entries in the calendar when recurring dates are used.
Calendar's views Row plugin picks up the entity associated with each result row, then generates a calendar entry for every occurrence from that entity. As Smart Date's Views integration is querying pre-generated occurrences, Calendar is actually doing this multiple times per entity.
I didn't spot this before, because Calendar has some simple logic to filter out duplicates (seems to have originated from https://www.drupal.org/project/calendar/issues/2699477#comment-11035135):
This works, but only if there are no other events within the same timeframe as the recurring series.
Replacing that logic [in Calendar] with something which tracks all the seen entity IDs works, but probably isn't an ideal approach!
Comment #11
mjchadwickWhen I try to use this patch (which fails via composer, but seems to work if you manually hack the module), I get the new arguments in contextual filters, but if I try to use one of them I get a "The handler for this item is broken or missing" error.
Comment #12
mandclu commentedIt seems like additional work is needed to get this working so updating the status to reflect that. Also trying to increase the visibility on this issue, since it would be great to get these modules working together.
Comment #13
veronicaseveryn commentedFound a minor issue with the FullDate argument. Views module provides it as "date_fulldate", and not "date_full_date" (for Datetime module it is defined as "datetime_full_date"). Updated a patch with just this change. The rest worked for me - allowed to select granular Views arguments for the Calendar module (version 1.x-dev as of Sep 30, 2023) with SmartDate (version 4.0.0-alpha1) and Drupal Core 9.5.11 .
Have the following patches in place to make things work together:
"drupal/calendar": {
"view_args always contains the current date when using ajax pager: https://www.drupal.org/project/calendar/issues/2858086": "https://www.drupal.org/files/issues/2022-04-19/calendar-view_args_ajax_f...",
"Check argument validity when using getDisplayForGranularity: https://www.drupal.org/project/calendar/issues/3197276": "https://www.drupal.org/files/issues/2022-10-06/calendar-getDisplayForGra...",
"Support for Smart Date, other contrib modules: https://www.drupal.org/project/calendar/issues/3177761": "https://www.drupal.org/files/issues/2022-06-13/3177761-6.calendar.Suppor..."
},
"drupal/smart_date": {
"Support Calendar module: https://www.drupal.org/project/smart_date/issues/3177760": "https://www.drupal.org/files/issues/2023-09-30/smart_date-support_calend..."
},
Comment #14
mandclu commentedThanks for the new patch, and the feedback. Based on your experience, would it make sense to move the Calendar issues to RTBC?
Comment #15
apkwilson commentedI've just set this up using #13 and the patch in #3177761-6: Support for Smart Date, other contrib modules. Aside from having to add the date contextual filter before selecting the calendar format, the experience was seamless. I'd say RTBC.
Comment #16
apkwilson commentedI did end up seeing duplicates calendar items, per grahamC in #10. I created another issue in the calendar queue, #3452532: Duplicate rows for some entities with multiple entity references, which addresses the problem in the way grahamC suggests.