foreach() argument must be of type array|object, bool given

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

Problem/Motivation

In process of upgrading Drupal 9 codebase to Drupal 10. Updated from 3.7.2 to 4.0.3 of smart date. Code in SmartDateTrait errors out for us when using custom code in a twig template.

Steps to reproduce

We have a node content type "Article" using a smart date field. On a twig template page we are printing `{{ content.field_sf_smart_dates|smart_date_format('date_only') }}` and `{{ content.field_sf_smart_dates|smart_date_format('time_only') }}` to display this dates. Switching to 4.0.3 results in the following error -

Warning: foreach() argument must be of type array|object, bool given in Drupal\smart_date\TwigExtension\SmartDateFormat->viewElements() (line 72 of modules/contrib/smart_date/src/SmartDateTrait.php).
Drupal\smart_date\TwigExtension\SmartDateFormat->viewElements(Object, 'en', Object) (Line: 57)
Drupal\smart_date\TwigExtension\SmartDateFormat->formatInput(Array, 'date_only') (Line: 162)
__TwigTemplate_81c9f140464c2a5bd7a9f9aac310d231->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array, Array) (Line: 40)
Twig\TemplateWrapper->render(Array) (Line: 53)

Downgraded to 3.7.2 for current purposes and issue is not there.

Happy to provide any additional information as needed.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

4.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States pbabin

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

Comments & Activities

Production build 0.71.5 2024