Provide a simple method to expand recurring events

Created on 12 March 2022, over 2 years ago
Updated 26 July 2024, 4 months ago

Problem/Motivation

As reported in #3254178: Manual Resaving of Node required for nodes after migration of repeating dates β†’ the current recurring date processing is part of the form processing, and as such is difficult to use for migration, or other content creation / modification that isn't through the standard UI.

Proposed resolution

Provide a method that can be used to generate additional instances. To make it non-destructive, it probably makes sense to first first reduce away repeating instances (as is done when preparing data for widgets) and then generate instances and potentially rules, as appropriate.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

4.1

Component

Smart Date Recur

Created by

πŸ‡¨πŸ‡¦Canada mandclu

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.

  • πŸ‡¨πŸ‡¦Canada mandclu

    I investigated the use of FieldItemBase::preSave but found that it's only able to operate on individual deltas, and as such doesn't have a broad enough scope to be able to generate additional instances. Altering the title and description of this issue to reflect an adjusted intent, refocusing on making it easier to migrate into recurring smart date values.

  • πŸ‡¨πŸ‡¦Canada mandclu

    New potential approach:

    Define a custom list builder, similar to Layout Builder Sections:
    https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/layou...
    https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/layou...

    Within the new list class, override the presave method to generate the instances:
    https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Field%21F...

    Need to determine what's the best way to reduce the values down, e.g. for editing. Maybe just a custom method, and then call that in the widget if it exists?

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    When I ran into this requirement as well, I did some digging and thought, why not just storing the first value as it would be provided by the form submission as well, and then leave the rest of the processing to the cron run, which should already create new instances when time goes by. If that process were to recognize that the recurring instances (i.e. the deltas) were missing, it would be creating them. Or did I get the purpose of that cron job wrong.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    I've tried that, and it seems to work just fine. I fixed the cron issue in πŸ› Cron in smart_date_recur not working due to property_exists Fixed locally and then created a new entity with a smart_date recurring field with this test code:

    $rule1 = clone SmartDateRule::load(1);
    unset($rule1->rid);
    $rule1->uuid = Crypt::randomBytesBase64();
    $rule1->instances = [
      'data' => [
        'value' => 1692619200,
        'end_value' => 1692662340,
      ],
    ];
    $rule1->enforceIsNew();
    $rule1->save();
    
    $opening = BookableCalendarOpening::create([
      'title' => 'Test 1',
      'status' => TRUE,
      'bookable_calendar' => 1,
      'date' => [
        [
          'value' => 1692619200,
          'end_value' => 1692662340,
          'duration' => 719,
          'rrule' => $rule1->id(),
          'rrule_index' => 0,
        ],
      ],
    ]);
    $opening->save();
    

    After that, I ran cron, and that created all the required instances as expected. Maybe that queue worked could be called in postSave to do this directly even before cron?

  • πŸ‡ΊπŸ‡ΈUnited States w01f

    I just updated a website to D10.3 that has a date-based header image and had to go in and resave all the nodes as well.

    Initially I thought it might be because the "Repeats every" value I was setting to 1 year, ends Never doesn't appear to save - it is blank again if you reopen after saving.

    But I didn't try just resaving without changing that field.

Production build 0.71.5 2024