Problem/Motivation

The recurring formatter has an option to list the "next instance" separately. This works well as long as there is an upcoming instance, but if all instances are in the past, nothing is shown. It may be desirable in some cases to show the most recent instance instead of nothing.

Proposed resolution

Allow the "next instance" to use the most recent instance if there are none in the future. It would likely be better to make this configurable, in case some sites would prefer to show nothing in this case.

Remaining tasks

  • Add a dependent configuration (probably default to true) to default to the most recent if no instances are upcoming, when a field is configured to show the next instance separately
  • Update the display logic to use the most recent instance in this case, and remove it from the "recent" instances displayed

Data model changes

  • Add a schema entry for the new configuration

Comments

mandclu created an issue. See original summary.

bburg’s picture

I considered making it a separate issue, but this seemed similar enough...

The recurring date formatter also seems to consider actively current events, e.g. events where the start time is before "now" and the end time is after, to be "recent".

e.g. as I am posting this, it is 5:20 pm on April 19th. I created an event in the starter kit modified to use recurring dates. I would like to be able to include a current date under upcoming. This also seems to affect "All-day" events.

Event with start and end times recurring today

Weekly on Monday at 10:00am for 4 times
RECENT

  • Mon, Apr 19 2021, 10am - 11pm

UPCOMING

  • Mon, Apr 26 2021, 10am - 11pm
  • Mon, May 3 2021, 10am - 11pm
  • Mon, May 10 2021, 10am - 11pm

Edit:

I am able to extend SmartDateRecurrenceFormatter and replace findNextInstance() with this snippet:

      $values = $instance->getValue();
      if ($end = $values['end_value']) {
        if ($end > $time) {
          $next_index = $index;
          break;
        }
      }
      else {
        if ($instance->value > $time) {
          $next_index = $index;
          break;
        }
      }

One note, these are private methods, so I need to re-implement the whole class, instead of extending it, and overriding the methods I need.

elizabeth.powell’s picture

Just jumping in to say I have the same need as @bburg above: I want events that are currently underway to display as upcoming, not "recent", and I came up with the same solution - extending SmartDateRecurrenceFormatter.

However in my case instead of reimplementing the entire class I've added a patch to my composer so that it makes the two methods protected rather than private. Long term, it would be nice if this could either be an option on the formatter, or if those methods could be made protected permanently.

mandclu’s picture

@elizabeth.powell is there a patch you could share? I would definitely consider updating the formatter.

elizabeth.powell’s picture

StatusFileSize
new2.44 KB

Well, I'm not sure how much use this will be to anyone else, but I've attached the patch that sets the two methods I override in my formatter as protected. (I did read the Drupal "Making a patch" guide but I apologise if this file is unsuitable in any way.)

This does not fix either of the problems in this issue but it does make it easier for a developer to override it.

mandclu’s picture

Version: 3.1.x-dev » 3.3.x-dev
Status: Active » Needs review
StatusFileSize
new2.15 KB

Here's an updated patch that includes the changes by @elizabeth.powell but also adds a configuration toggle to treat current events as upcoming.

Please test and let me know if this addresses your use case.

  • mandclu committed 6e6a563 on 3.4.x
    Issue #3199889 by mandclu, elizabeth.powell: Recurring Formatter: have "...
mandclu’s picture

Status: Needs review » Fixed

Merged in.

elizabeth.powell’s picture

Sorry, I only just got the chance to test this out! I just installed 3.4@beta and it works exactly as described, thanks very much for this.

Status: Fixed » Closed (fixed)

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