Webform element preview serialize() error in Build mode

Created on 3 November 2023, 8 months ago

Problem/Motivation

There is an PHP exception when toggling "Show preview"/"Hide preview" button, when adding a new webform element.
Using PHP 7.4 with Webform 6.1.8 and Office hours 1.12.
Using PHP 8.1 with Webform 6.2.0 and Office hours 1.12.

Actual stack trace:
TypeError: Drupal\office_hours\Plugin\WebformElement\WebformOfficeHours::serialize(): Argument #1 ($office_hours) must be of type array, null given, called in /var/www/html/web/modules/contrib/office_hours/src/Plugin/WebformElement/WebformOfficeHours.php on line 204 in Drupal\office_hours\Plugin\WebformElement\WebformOfficeHours::serialize() (line 388 of /var/www/html/web/modules/contrib/office_hours/src/Plugin/WebformElement/WebformOfficeHours.php)

Steps to reproduce

Works same for both version of PHP:

  1. composer create-project drupal/recommended-project:^9 ./
  2. composer require drupal/webform drupal/office_hours
  3. Install the site (drush si -y)
  4. drush en webform_ui office_hours -y
  5. Login as admin, and navigate to Structure -> Webforms
  6. Click on existing "Contact" webform, and switch to "Build" tab.
  7. Click on button "Add element"
  8. Click on button "Show preview" which is on top right corner of the modal.
  9. Now click on "Hide preview" at the same location. Nothing will happen. There is PHP error logged.

Proposed resolution

Add null coalesce operator.

πŸ› Bug report
Status

Fixed

Version

1.12

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada igorbiki

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

Comments & Activities

Production build 0.69.0 2024