Unabled to add PhoneNumber to Webform with allowed number of values higher than one

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

Problem/Motivation

When trying to add a PhoneNumber (as WebformElement) on a Webform and setting the allowed number of values to a fixed number higher than one or unlimited, the element fails to save due to the following error:

Unable to render elements, please view the below message(s) and the error log.
* Unsupported operand types: string + array
There has been error validating the elements. You may need to edit the YAML source to resolve the issue.

The problem originates from \Drupal\webform\Element\WebformMultiple::setElementDefaultValue and how it sets the #default_value key
on the $element. This function is is called multiple times by \Drupal\webform\Element\WebformMultiple::setElementRowDefaultValueRecursive, which
seems to receive different values to pass to setElementDefaultValue as default: string or null, depending on the loop item in the foreach.

Current implementation of \Drupal\phone_number\Plugin\WebformElement\PhoneNumber::setDefaultValue only works if
the #default_value key isn't set or is an array.

Steps to reproduce

See Problem/Motivation.

Proposed resolution

Handle the cases as described in Problem/Motivation.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇧🇪Belgium andreasderijcke Antwerpen / Gent

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

Comments & Activities

Production build 0.71.5 2024