Problem/Motivation

When using the Recurring formatter on an event with per minute/per hour frequency, the following fatal exception is thrown.

Error: Call to a member function getValue() on array in Drupal\smart_date_recur\Plugin\Field\FieldFormatter\SmartDateRecurrenceFormatter->viewElements() (line 286 of modules/contrib/smart_date/modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php).

This is because the $instances_nested variable returns a date-indexed array of instances, meaning all further calls making use of $instances will fail because it no longer contains a flat array of field instances.

Steps to reproduce

Enable recurring event frequency for the field by Minutes or Hourly.
While making use of the Recurring formatter.

Add a date which repeats every 3 minutes and ends after 2 times.

When you attempt to view it on the frontend, the page will throw a fatal exception.

Proposed resolution

I'm not exactly sure what the preferred approach is.

We could add appropriate error handling or potentially the $instances_nested variable if necessary.

Remaining tasks

Provide issue fork/patch

User interface changes

N/A

Issue fork smart_date-3399865

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

codebymikey created an issue. See original summary.

codebymikey’s picture

Status: Active » Needs review
StatusFileSize
new1.19 KB

Attached an approach which ensures that the $instances array is in a consistent state.

  • mandclu committed 8f0b9af4 on 4.1.x
    Issue #3399865 by codebymikey, mandclu: Recurring formatter: fatal error...
mandclu’s picture

I decided to do a little more refactoring but I believe this is essentially the solution you provided. Thanks for identifying this, and for providing a fix.

mandclu’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.