Hide seconds causes PHP warning

Created on 22 July 2024, 5 months ago
Updated 1 August 2024, 5 months ago

Problem/Motivation

Editing a node with a smart_date widget with hide seconds set gives four PHP warnings if the date field is empty.

  • Warning: Undefined variable $values in Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formElement() (line 171 of modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php).
  • Warning: Trying to access array offset on value of type null in Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formElement() (line 171 of modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php).
  • Warning: Undefined variable $values in Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formElement() (line 171 of modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php).
  • Warning: Trying to access array offset on value of type null in Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formElement() (line 171 of modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php).

Steps to reproduce

1. Define content type with datetime field using smart_date widget with "hide seconds" set.
2. Create new content of that type
3. NOTE the errors displayed and logged when the edit form is displayed.

Proposed resolution

See patch.

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Postponed: needs info

Version

4.1

Component

Code

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024