- π¬π§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.