Display recurrence frequency instead of date in twig template

Created on 22 May 2023, over 1 year ago
Updated 25 May 2023, over 1 year ago

Problem/Motivation

I want to display a recurring date's frequency instead of the actual date(s).

Steps to reproduce

I have an Event node with a Smart Date Range field. I've set it to repeat Daily. Viewing the Event shows all dates as expected.

[Screenshot: Default Multiple Day Display]

I implemented a custom Smart Date formatter and am using it like event_date|smart_date_format('my_custom_formatter') so it only shows the first instance on the Event node.

[Screenshot: Custom First Instance]

So far so good!

However, is there a way to instead display the SmartDateRule's $freq property?

[Screenshot: Custom Recurrence Frequency]

✨ Feature request
Status

Active

Version

4.0

Component

Smart Date Recur

Created by

πŸ‡ΊπŸ‡ΈUnited States mjchadwick

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

Comments & Activities

  • Issue created by @mjchadwick
  • πŸ‡ΊπŸ‡ΈUnited States mjchadwick

    I figured it out!

    In case anyone else wanted to know:

    1. In your theme or module code, add a reference to SmartDateRule:
    use Drupal\smart_date_recur\Entity\SmartDateRule;
    2. Grab the recurring rule ID:
    $rule = $node->[smart_date_field_machine_name][0]->get('rrule')->getValue();
    3. Load the SmartDateRule using that ID:
    $rrule = SmartDateRule::load($rule);
    4. Grab the freq property
    $freq = $rrule->get('freq')->value;

    I did some further futzing to get my final output, but that was the key for me.

Production build 0.71.5 2024