Recurring date field renders original date, not repeated rule

Created on 1 June 2022, about 2 years ago
Updated 28 January 2024, 5 months ago

Problem/Motivation

The date from the recurring field β†’ is not correctly rendered when the date repeats. The original date of the event is rendered, not the evaluated rule for the recurring event.

Steps to reproduce

* Add recurring date field
* Create a node with recurring date in the past & a rule that creates multiple future events. Ex: Start date 2022-04-18 12:00, end date 2022-04-18 15:00, event repeats every Monday for a year.
* Configure display to use the basic date interpreter, show maximum of 1 occurrence
* In this display, the next sequential date is rendered, as of June 1st it would be June 6th
* Configure the display to use Add to Cal
* In this display, the original dates (in the past) are rendered, April 18th

Proposed resolution

* Apply recurring date interpreter field before rendering the field

I created a custom solution as a workaround using hook_preprocess_node
When I used $node->get('field_recurring_date')->getValues()[0]['start_date'] I got the original date.
Using value from content field $variables['content']['field_recurring_date'][0]['#occurrences'][0]['start_date']['#attributes']['datetime'] gave me the desired value. I suspect that the recurring date module processes the values for display before it is placed into the content variable.

User interface changes

This may be a separate issue, but it would be nice to add the format options from recurring date fields to add to cal formatter, when it's used on the recurring date field. Useful configurations in order of priority:
* Recurring date interpreter (unless auto built in)
* Show maximum number of occurrences per field
* Start and end date format
* Same day end date format
* Non-Repeating Date format

πŸ› Bug report
Status

Active

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States makbeta

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom very_random_man

    I found that i could either use the date_recur formatter or the addtocal formatter. Rather than try to combine them I created a two fields, one of which was hidden from all forms and populated from the other. Then I could use both in the entity display, one as a the formatted date and the other as a dedicated AddToCal button.

    The only problem i had was that only the original date was used in the calendar event and the repeating dates were ignored. On further inspection it looks like repeating dates aren't supported by the underlying library (https://github.com/spatie/calendar-links/issues/188).

    I used the following code to use the next occurrence date for the calendar event.

    /**
     * Implements hook_addtocal_links_alter().
     */
    function MODULENAME_addtocal_links_alter(array &$links, array $context) {
    
      $now = new DateTime();
      $next_occurrence = NULL;
    
      /** @var \Drupal\date_recur\DateRange $occurrence */
      foreach ($context['items'][0]->occurrences as $occurrence) {
        $next_occurrence = $occurrence;
        if ($occurrence->getStart() > $now) {
          break;
        }
      }
    
      if ($next_occurrence) {
        $old_addtocal_link = clone $links['#addtocal_link'];
    
        $links['#addtocal_link'] = \Spatie\CalendarLinks\Link::create($old_addtocal_link->title, $next_occurrence->getStart(), $next_occurrence->getEnd());
        $links['#addtocal_link']->address($old_addtocal_link->address);
        $links['#addtocal_link']->description($old_addtocal_link->description);
      }
    }
    

    Seems a bit clunky but it does the job.

Production build 0.69.0 2024