Hello, great module, thanks for all the work!
I have a Smart Date Recur setup that Im hoping for advice or direction on. The field display setting is set to 'Recurring', which works great when a single date value is set with recurring dates, it works perfectly to remove any date in the past and only show the next and any upcoming dates.
But, in a scenario where multiple individual dates are entered (the date field allows multiple), with no recurs, the dates are all shown, regardless if the date has past or not. Not sure if this is the intentional output, or if there is a setting to stop past dates showing, haven't been able to see anything so far.
Thanks in advance for any help.
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | smart_date-upcoming_past_formatter-3251171-35.patch | 13.97 KB | marcvangend |
| #33 | Capture3.PNG | 31.64 KB | lindsay.wils |
| #33 | Capture2.PNG | 19.21 KB | lindsay.wils |
| #33 | Capture.PNG | 31.96 KB | lindsay.wils |
| #32 | smart_date-upcoming_past_formatter-3251171-32.patch | 13.97 KB | mandclu |
Comments
Comment #2
mandclu commentedBy design the Recurring formatter does its work within the context of a specific recurrence rule. It would be possible to use the same (or at least, extremely similar) logic to show a similar split of past/upcoming dates without consideration of recurring rules, as a general-purpose formatter.
Moving this to a feature request, and if you have any thoughts on what would be a good name for this new formatter, please share.
Comment #3
lindsay.wils commentedThank you for the quick response.
It is a tough one, as there is likely going to be a scenario where a date field is set to have the option for multiple/unlimited rows, so could contain once off dates, as well as recurring dates, maybe not on the same node, but in my case, definitely on the same content type / field.
We are using it on a basic events calendar, so some are recurring, some are single, some are multiple single dates.
I see your thought about having a different formatter, but in my case, I would still be needing to use the Recurring formatter. I wonder if there is a way in the logic of this formatter to only show upcoming dates outside of recurs, or an option to hide all past dates, regardless if they are recurring or not. But I get this may not be possible, as you said, the logic is set within the recur rule. So not sure what option there is on the base date.
Here is an example of my scenario just to make sure Im clear
Event with recurring date (hides all past occurances)
https://redjacketresorts.com/events/finger-painting
Event with multiple single dates (shows past date rows)
https://redjacketresorts.com/events/campfire-0
(I get that this specific one could be set using recurs and overrides, but it illustrates the issue)
Thank you for your time.
Comment #4
mandclu commentedTo clarify, what I was thinking is similar to the standard Smart Date formatter with "force chronological" enabled, but then would would be able to set a limit on the number of upcoming or past events that would be shown, whether within a recurring rule or not. How is that different from what you want?
Comment #5
lindsay.wils commentedYes that does sound like it would be a good solution, as long as we would still get the recurring display, but with the ability to hide past single dates, or recur occurrences.
Basically the overall goal would be a setting to never show past dates, regardless of recurring or not.
Thank you for taking the time to discuss.
Comment #6
mandclu commentedHere's a patch that provides a proof-of-concept for what I had in mind. It's similar to the Recurring formatter but it won't group together dates in the same recurring rule. As such, you should be able to set it to not display any past events.
That said, while I was working on this, it occurred to me that I could potentially provide the same functionality within the existing Recurring formatter if "force chronological" is selected (which I don't think does anything currently). The downside to that is that this functionality is potentially useful to sites not using recurring dates.
Comment #7
lindsay.wils commentedThank you so much for your work here and responding so timely. This is actually perfect! And working better than I had even expected.
Maybe it was my lack of understanding on the available formatters, but this is working great, what I am getting is the next date separated out and then all future dates, whether they are from a repeat rule, or from singularly entered dates, all grouped together withing the 'Upcoming' block. This is the exact scenario I was hoping for, and will work perfectly for my client, who has events that are all over the place and not always following a specific recurring format.
Currently, if they enter separate date rows, each with their own recur, plus single date rows, we get a messy output of all individual rows, this fully solves that issue.
Thank you so much!
Comment #8
lindsay.wils commentedOne issue Ive just found, is that if the node display for the field has a label set to be shown, it isnt actually showing. Oddly, any preprocess function i try to run on the field within hook_preprocess_field seems to not being run.
Not sure if this is something you were aware of as it was just a proof of concept. I tried to look into the formatter plugin, but Ill be honest, I havent worked with these before, so might be a quick and obvious thing for you.
Thank you again.
Comment #9
mandclu commentedGood catch! Fortunately it was also an easy fix. An updated patch is attached, please review.
What are your thoughts about allowing the existing Recurring formatter to behave this way if the "Force chronological" option is set, instead of having a separate formatter?
Comment #10
lindsay.wils commentedThank you, glad it was an easy fix, I'll check it out hopefully later on today.
I'm all for having it in the existing Recurring formatter, but not entirely sure about how to name this option. "Force chronological" isnt exactly obvious for the functionality, so maybe would require a description under the checkbox. You mentioned this setting is currently not doing anything within this formatter, so maybe renaming to something along the lines of 'Group multiple rows', or 'Group all dates instances'. or something like that.
Comment #11
lindsay.wils commentedJust had a play with this, and the previous issue mentioned with the labels is resolved and preprocess functions are working as expected, thank you.
I did come across another potential issue, which is a bit of an outlier. When a single non-recurring date is set as an all day date and spans multiple days, ie start date 1 Dec - end date 24 Dec, on the full display mode, the date is hidden completely. Im assuming as this is seeing the start date as in the past, so it is being removed by the formatter.
Sounds like potentially a difficult one to allow for.
Comment #12
mandclu commentedI believe the Recurring formatter does include an option to treat events that are underway as upcoming, which sounds like it would resolve what you've observed. I'll try merging the formatter next and we'll see how that works.
Comment #13
lindsay.wils commentedPerfect, thank you for that, I had previously seen that setting before, but hadn't used it and forgot about it, that worked! Thanks again.
Comment #14
mandclu commentedOK here's a new patch that should provide the same merged output within the existing Recurring Formatter, if the "Force chronological" option is selected. For the sake of consistency, I decided to keep the label the same, but updated the description:
I was thinking that another option here might be updating the name of the formatter, to reflect the fact that it can be useful for non-recurring, multivalued events. Either "Upcoming / Past" as we had previously used for the new formatter, or something like "Subset"?
Comment #15
mandclu commentedI ended up finding a couple of bugs in the previous patch, here's an updated version.
Comment #16
lindsay.wils commentedThanks for this. I just tried applying the patch using Composer and it failed, not entirely sure why, as it doesnt give any useful error. I tried (with my limited knowledge) trying to apply it manually and it also didnt work, asking me to manually merge chunks of code.
Sorry, this doesn't give you much to go on.
Comment #17
mandclu commentedWhat version are you trying to apply the patch to? I just tried on a fresh install of 3.5.0-beta4 and it installed without error.
Comment #18
lindsay.wils commentedSorry, I was using 3.4.3, patch applies fine on 3.5.0-beta4.
Couple things.
- The field description has a grammar error, 'as s single group' instead of 'as a single group'
- Im getting a php warning message
Notice: Undefined index: instances in Drupal\smart_date_recur\Plugin\Field\FieldFormatter\SmartDateRecurrenceFormatter->buildOutput() (line 349 of modules/contrib/smart_date/modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php).
This seems to be with any date set, regardless of having recurring rule or not.
Thanks again.
Comment #19
mandclu commentedThanks for the thorough feedback! Here's a new patch that should fix the two issues you identified.
Comment #20
lindsay.wils commentedThank you.
Unfortunately getting a different error now after running on 3.5.0-beta4
Error: Class 'Drupal\smart_date\Plugin\Field\FieldType\SmartDateItem' not found in Drupal\field\FieldStorageConfigStorage->mapFromStorageRecords() (line 169 of core/modules/field/src/FieldStorageConfigStorage.php).
Comment #21
mandclu commentedHmmm can you provide steps to reproduce that?
Comment #22
lindsay.wils commentedOdd, I went back and applied what I thought to be the same steps to apply the patch, and this time no issue, so clearly did something wrong.
This looks to be working great with multiple single dates and recurs, but when just 1 single date is set, I am getting a warning
Warning: array_shift() expects parameter 1 to be array, null given in Drupal\smart_date_recur\Plugin\Field\FieldFormatter\SmartDateRecurrenceFormatter->subsetInstances() (line 321 of modules/contrib/smart_date/modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php).
Comment #23
mandclu commentedAnother good find! I really appreciate you testing this new functionality with cases I might not have though of. Attached is a new patch, please let me know if you can find any additional issues.
Comment #24
lindsay.wils commentedNot a problem at all, thanks for your continued work on the updates!
Latest warning is gone. Though Im seeing one of the previously reported issues where the field label isn't displaying, likely because the fix wasn't brought over when the update was moved to the Recurring Formatter maybe?
Thanks again
Comment #25
mandclu commentedExactly right, it just needed the same simple fix. New patch attached
Comment #26
lindsay.wils commentedThank you yet again!
But sorry yet again.. I think I have found another issue. Though this does not seem to be specific to this patch, rather specific to 3.5.0-beta4.
If I set one single, non-recurring date to be occurring later on during the current day, the date does not show. I tried using the setting 'Treat current events as upcoming' and this did not make a difference. I downgraded back to 3.4.3 and the date showed correctly. Are you able to confirm this?
If necessary, I can create a new ticket tagged specifically for this issue?
Thanks again.
Comment #27
mandclu commentedIf this new issue isn't specific to this patch, then please record that as a new ticket with as much detail on how to reproduce as possible.
If there aren't any additional issues specific to this patch, please mark this as RTBC. Thanks!
Comment #28
lindsay.wils commentedTo be honest, after more testing, I'm now not entirely sure that it isn't related to this patch.
With a fresh install of 3.5.0-beta4
- Create a node with a single non-recuring date for a time later on the current day
- node display set to Recurring formatter with Force chronological, Show next instance separately, Treat current events as upcoming all checked
I get a bunch of warnings.
Apply the patch from #25, all the warnings are gone, but the date does not display, the field does.
If i set the date to tomorrow, it shows, or if I apply any repeat rule for future dates, they show, it just seems to be when the date is on the same day.
It seems that any date set to the current day looks as though it is seen as in the past, regardless of the time being in the future or not.
I hope that is enough information for you, again, thanks very much for your time here, sorry to be finding issues :)
Comment #29
mandclu commentedI appreciate your thorough testing and feedback! I would much prefer to identify any problems now, instead after a release.
That said, I'm unable to reproduce your most recent problem. If a single, non-recurring event for later today with "Show next instance separately" selected, the value shows normally:

If I deselect "Show next instance separately", the instance shows as upcoming:

In either case, changing whether or not "Show next instance separately" is on doesn't appear to change the output. Is there something else I need to do to reproduce what you're seeing?
Comment #30
mandclu commentedDuring my own testing I noticed an issue with the instance delta values being reset, which was causing problems with the Date Augmenter API. It wasn't a big change, so decided to roll that into the work being done in this issue. Please test with this patch instead of the one in #25.
Comment #31
lindsay.wils commentedThanks for looking further into this. The issue I am seeing seems to be related to what timezone I have the site set in. We generally leave our timezones always set as UTC to have a standard base, then if we have to do anything in our code with timezones, we work from that, so it is the same between projects.
With 3.4.3, I am not seeing issues, nor with 3.5.0-beta4, a date set just an hour in advance on the same day shows correctly, but after applying the patch, then it is seen as it is in the past. Assumption being that the new logic is taking into consideration the timezone of the site to determine what is past and future, so with mine being set is UTC, it sees the date as already being past. I confirmed this by setting the time to just ahead of current UTC time, which then the date showed as expected within the formatter.
Not sure of a solution here, as this is obviously the logic you are using in this patch to determine what is past/future, and this may just be an isolated issue for me for incorrectly using UTC time for the site default. My issue now, if I change my timezone, all existing times set on nodes then get updated to stay in sync with what they would have been, which obviously causes me issues in having to reset all the events times.
Hope this information helps and understand if this is not something you can account for, as it obviously makes sense to be using the sites timezone, but wonder what logic was being used previously to determine past/future?
Thanks
Comment #32
mandclu commentedI have observed an issue where sometimes the widget settings aren't properly retrieved within helper functions, so here's a patch which retrieves the "current upcoming" as part of the initial setup for the formatter. Not sure this was the cause of what you've observed, but it's worth a try, and also more consistent with how other settings are handled in the formatter.
That said, I'm still not sure I understand the problem you're seeing. As it happens the site I use for development is set to use use UTC, so I tried creating a new date. The field was set to use "next hour" as the default value, so it created a date ~40 min in the future. It saved, and displayed as upcoming. I also tried manually setting the event timezone to my actual timezone and then changing the event time to the equivalent local time, and it also showed as upcoming.
In answer to your question about the logic to determine past/future events, both the original and the patched logic are using timestamps for the comparison, so the timezones on the events shouldn't matter.
Any chance you could provide detailed step-by-step instructions on how to reproduce the problem you're seeing on a fresh install of Drupal 9?
Comment #33
lindsay.wils commentedJust tested in a fresh install of Drupal, Bartik theme, and reproduced the same issue. All I can say is, for whatever reason, it seems to be using UTC time to determine if a date is past or future. Which would make sense, as my default site timezone is set to UTC.
If i change the field settings to have Default date set as Current date, then when creating a new node, UTC time is used. If i change my site timezone to Vancouver (PST), then this is used and dates work as expected. I tried changing the display settings to my timezone with 'Time zone override', but this made no difference.
When you say 'I also tried manually setting the event timezone to my actual timezone', how were you doing this? The only place I see a timezone setting is in the display mode, maybe this is what you mean?
Adding a screenshot of my settings. And to be clear, the field settings are set for unlimited values.
Sorry to drag this out, not sure what it is in my settings that is differing, clearly something that I am missing or not understanding.
Thanks again.
Comment #34
mandclu commentedOK, here's the full set of steps I just tried:
In my testing the event shows as upcoming.
When I mentioned previously about setting the event timezone, I was referring to changing the field widget to "Date and time range with timezone" and then setting the event's timezone to Toronto.
I'm not sure I understand the problem here. It sounds as though if your site is using UTC as its timezone, then when you create an event it assumes the times are for UTC. If you create an event on a site using UTC as its timezone and set the time as something upcoming in Vancouver time, that's actually in the past in UTC.
Comment #35
marcvangendI got a warning
Warning: Undefined array key "rule" in Drupal\smart_date_recur\Plugin\Field\FieldFormatter\SmartDateRecurrenceFormatter->viewElements() (line 253 of modules/contrib/smart_date/modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php).when saving a node with a recurring date. Wrapping the if condition in !empty() solved it. Here's a new patch.Comment #37
mandclu commented@marcvangend thanks for identifying that, and for the updated patch. Since that was the only issue you found, classifying this as ready for a new release, if more work is still needed we can fix it before the first stable release of the 3.5.x branch.
Comment #38
marcvangendThanks. Indeed I didn't find other issues with the patch. If I do, I'll let you know.
Comment #39
lindsay.wils commentedHello, thanks for the futher patches and release.
Im really sorry to be continuing this, but I have followed your steps as exactly outlined, and I am still seeing the same results
1. Fresh install of Drupal, UTC timezone
2. Install 3.5.0-rc1, enable Smart Date Starter Kit and and Smart Date Recurring
3. Update the When field on the Event Content Type to allow recurring values and use the Recurring formatter with "Force chronological" enabled
4. Create an event within the next hour
My event does not show the date as upcoming. If I have 'Recent Instances' set to any number, the date shows as recent, if I set this to 0, the date does not show.
Yes, that is exactly what I am saying. The sites timezone is set to UTC, the field settings for the When field has the Default date set as 'Next hour'. When creating a new event, the dates default value is set as the next hour of UTC time. Not my current time. If I change the sites timezone to Vancouver, then a new events default date is shown correctly to Vancouver time.
So, when creating a new event in PST time, the site is seeing this as in the past for UTC time, and then not showing the date as upcoming. If I set the time to something that would be upcoming in UTC, then the date shows as upcoming.
I really cannot understand what is different here as to why we are getting completely different results.
Do you get the same results when you create a new content type with a new field, rather than using the starter kit?
Thanks again.
Comment #40
lindsay.wils commentedIve just installed the latest release on the site Ive been working on, and I saw the same results, though Ive changed the Form display for the field to 'Date and time range with timezone' and have forced the timezone to what I want and this looks to have solved all the time display issues. The dates are now specific to my timezone and no confusion with UTC. Seems like this is the fix, which kind of makes sense.
Thanks again for all your work on this, really appreciate it, and sorry for any wasted time I may have caused.
Comment #41
mandclu commentedI'm glad you found a solution that works for you, and really appreciate all of your feedback!