Problem/Motivation
TypeError: strlen(): Argument #1 ($string) must be of type string, array given in strlen() (line 395 of core/lib/Drupal/Component/Utility/Unicode.php)
The problem is in template_preprocess_field_multiple_value_form() where there is an empty array in the header.
$header = [
[
'data' => [
'#type' => 'html_tag',
'#tag' => 'h4',
'#value' => $element['#title'],
'#attributes' => $header_attributes,
],
'colspan' => 2,
'class' => ['field-label'],
],
[], // Problem is here.
t('Order', [], ['context' => 'Sort order']),
];
Steps to reproduce
To be added
Proposed resolution
Remove the cell and increase the colspan of the previous cell.
Merge request link
https://git.drupalcode.org/project/drupal/-/merge_requests/6323
Remaining tasks
Add test coverage
User interface changes
Removal of empty header cell.
API changes
None.
Data model changes
None.
Release notes snippet
TBD
Comments
Comment #2
larowlanAre you able to reproduce this with vanilla Drupal core?
Can you please provide steps to reproduce starting f from install Drupal?
Thanks
Comment #3
longwaveThe extra
[]was added in #1038316: Allow for deletion of a single value of a multiple value field but not sure how to reproduce the issue.Comment #4
danielhonrade commentedI am having the same problem, I don't know why because a vanilla Drupal install didn't get that error, but adding an override of that function and making [] to ' ' fixed it.
Comment #5
gaddman commentedAre you using Bootsrap theme? May be a duplicate of #3409370: PHP error when form has entity reference in Drupal 10.2.0.
Comment #6
aduthois commentedYes, Patch Issues-3409370-PHP-error-when-form-has-entity-reference.patch
solve the problem but for me is a core problem not bootstrap theme problem :
function template_preprocess_field_multiple_value_form add a empty array, why ?
Comment #7
gaddman commentedComment #8
gaddman commented@larowlan - steps to reproduce using Bootstrap theme are described in #3409370: PHP error when form has entity reference in Drupal 10.2.0, reproduced here:
/admin/appearance./node/add/article) - page loads OK./node/add/article) - page fails to load and PHP error is observed in log.To @aduthois' point - is this considered a core issue or should the fix be in Bootstrap?
Comment #9
aduthois commentedI suppose if drupal core has a good reason to add an empty array, boostrap should adapt to the case. So ok for this patch
Comment #10
liam morlandI am having this problem.
The documentation for
template_preprocess_table()says that the array values in the#headerproperty need to be either a string or an array with certain keys. An empty array is not consistent with the documentation. Correcting it makes sense for this reason. The attached patch does this and fixes the issue for me.Comment #11
liam morlandThere is an underlying issue here as well: As it is, there is an empty
thelement created. That shouldn't be. One option would be to give the column a title, perhaps "Actions". Another would be to remove the cell and increase thecolspanof the previous one; see this patch for implementation.Comment #12
smustgrave commentedRecommend using an MR, as DrupalCI is less supported and may not be as accurate in my opinion.
But currently the patch is showing failures.
Also will need test coverage
Issue summary should be updated with standard template. Added the template but will have to be updated.
Comment #14
liam morlandI have created a merge request with the patches.
Tests in the merge request are passing.
Issue template updated.
Comment #15
clota01 commentedHi! Comment #10: drupal-header_array_empty-3409752-10.patch works for me. Thanks!
Comment #16
hdnag commentedHello,
I have the same issue but for D9.5.11 :
The patches are non applicables. Do you have an idea to solve that issue ?
Comment #17
liam morland@hdnag your issue must be caused by something else. This issue is about a bug introduced in Drupal 10.2. Drupal 9 in no longer supported.
Comment #18
m_hobby commented@Liam Morland, thanks #10 in my case resolves the bug.
@smustgrave, is there anything else (test coverage?) that is needed to get this issue across the line?
Many thanks.
Comment #19
liam morlandIt should have a test.
Comment #21
fathima.s commentedSame error occurs with bootsrap5 theme.Above patches didnt work for me .Is there any other way to fix in bootstrap5
"TypeError: strlen(): Argument #1 ($string) must be of type string, array given in strlen() (line 395 of core/lib/Drupal/Component/Utility/Unicode.php)."
Comment #22
kopeboyHaving the same error at /admin/config/services/openapi
Comment #23
shweta__sharma commented