- Issue created by @dnt
In a multi-page webform we sometimes experience the problem that array('value' => null)
is used as value. It seems to happen only when the field is not on the visible/submitted page, i.e. it's not part of $_POST
. We've seen this problem at two spots:
1. On webform submission. This results in the string Array
being persisted as value overriding a previous value, if any.
2. In \Drupal\editor\Editor. Here it results in a PHP error:
TypeError: strlen(): Argument #1 ($string) must be of type string, array given in strlen() (line 395 of /var/www/vhosts/civicrm.mintzukunft.de/httpdocs/pro/drupal/web/core/lib/Drupal/Component/Utility/Unicode.php).
At both spots I've added code to produce some debug logs. Interestingly at 2 the attribute #default_value
in $element
contains array('value' => null)
, though that's not what is defined in the webform. The field definition in the webform is like this:
field_name:
'#type': text_format
'#title': 'Some Title'
'#default_value':
value: '<p>Some Text</p>'
format: filtered_html
'#allowed_formats':
filtered_html: filtered_html
By contrast $element
contains (JSON encoded and reduced to only some properties):
{
"#type": "text_format",
"#default_value": {
"value": null
},
"#allowed_formats": {
"filtered_html": "filtered_html"
},
"#webform_plugin_id": "text_format",
"value": {
"#type": "textarea",
"#default_value": {
"value": null
},
"#allowed_formats": {
"filtered_html": "filtered_html"
},
"#webform_plugin_id": "text_format",
"#value": {
"value": null
},
},
"format": {
"#type": "container",
"format": {
"#type": "select",
"#default_value": "filtered_html",
"#value": "filtered_html",
},
"editor": {
"#type": "hidden",
"#value": "filtered_html",
}
},
"#format": "filtered_html",
}
Unfortunately I wasn't able to reproduce it myself, yet.
Currently the only thing I was able to workaround the issue was adding a `preSave()` method to \Drupal\webform\Plugin\WebformElement\TextFormat
that replaces the value with the previously stored value or the empty string, and to modify \Drupal\editor\Element::preRenderTextFormat
.
Active
6.2
Code