- π¨π¦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.