Problem/Motivation
The Claro theme throws TypeError with a custom table block:
TypeError: in_array(): Argument #2 ($haystack) must be of type array, string given in in_array() (line 196 of /var/www/core/themes/claro/src/ClaroPreRender.php).
Steps to reproduce
- Enable Claro Theme as a default theme.
- Create a custom Block in a custom module to render a table with a class attribute as a string:
class CustomBlock extends BlockBase { /** * {@inheritdoc} */ public function build() { return [ '#type' => 'table', '#attributes' => [ 'class' => 'classname' ] ]; } } - Place the block on the page.
Proposed resolution
Add a check to the tablePositionSticky method in the Claro theme to avoid calling the array function on a non-array variable.
Remaining tasks
- Review MR
- Commit
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3419621-TEST-ONLY-FAIL.patch | 1.55 KB | dburiak |
Issue fork drupal-3419621
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ryanbuckley@gmail.com commentedComment #5
sijumpk commented'
class' attribute should be an array. Seems like in case of Geofield Map, its passing a string instead of an array. Because of that this error is happening. Noticed that inside core code, there are some places where double checking for array elements are happening. Eg inside ClaroPreRender::verticalTabs$groups_are_present = isset($element['group']['#groups']) && is_array($element['group']['#groups']);So adding the same type of checking for $
element['#attributes']['class']also.Comment #6
smustgrave commentedSeems like a bug on GeoMap module.
Comment #7
dburiak commentedHere is the test-only patch showing the issue.
Without patching, the test will fail on Drupal 10.2.x
In the CI I don't see an option to run a test with 10.2.x version. Only 10.1.x available.
Comment #8
dburiak commentedUpdated test-only patch with fixed coding standards.
Comment #9
dburiak commentedComment #10
smustgrave commentedLeft a small comment but can you update MR for 11.x please
Comment #12
anpolimus@smustgrave, do you mean creating a new MR against 11.x or updating this one from 10.x to 11.x?
Comment #13
smustgrave commentedUpdating existing one to 11.x would be best.
Comment #20
dburiak commentedAdded MR to 11.x: https://git.drupalcode.org/issue/drupal-3419621/-/tree/3419621-typeerror...
Please review.
Comment #21
dburiak commentedComment #22
smustgrave commentedIssue summary appears to be missing proposed solution section.
Also wonder if there's been a backtrace to see what's calling this with a string. In case we covering up a larger issue.
Comment #23
lpeabody commentedAs an FYI this error is resolved in the case of the Geofield Map module in version 3.0.15 https://git.drupalcode.org/project/geofield_map/-/compare/3.0.14...3.0.1...
Comment #24
dburiak commentedComment #25
dburiak commented@smustgrave The string in the original issue was calling from Geofield Map module (already fixed). The summary is updated with a proposed solution section.
Comment #26
dburiak commentedComment #27
smustgrave commentedBut what are the steps to reproduce in core without the geofield module?
There are 2 MRs up, can one please be hidden.
Comment #29
dburiak commentedComment #30
dburiak commented@smustgrave the summary is updated. Please review.
Comment #31
dburiak commentedComment #32
pameeela commentedI think the IS is OK now.
Comment #33
smustgrave commentedThanks @pameeela for updating that.
Test only feature shows the issue
Additional check seems to solve the issue.
Comment #34
alexpottI left some small nits on the MR to address. Once they are this can go back to rtbc.
Comment #35
dburiak commentedComment #36
dburiak commentedComment #37
nod_Still need to remove the try/catch. Tests are fast now, it's not a problem if it stops everything else after.
Comment #38
pameeela commentedAccepted the suggestion to remove the try/catch, the tests are failing but I can't see that it's related to this?
Comment #39
smustgrave commentedMR just needed a rebase, all green now!
Comment #44
nod_Committed 7e28ed5 and pushed to 11.x. Thanks!