Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 CreditAttribution: ryanbuckley@gmail.com commentedComment #5
sijumpk CreditAttribution: sijumpk at QED42 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 CreditAttribution: smustgrave at Mobomo commentedSeems like a bug on GeoMap module.
Comment #7
dburiak CreditAttribution: dburiak at ImageX 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 CreditAttribution: dburiak at ImageX commentedUpdated test-only patch with fixed coding standards.
Comment #9
dburiak CreditAttribution: dburiak at ImageX commentedComment #10
smustgrave CreditAttribution: smustgrave at Mobomo 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 CreditAttribution: smustgrave at Mobomo commentedUpdating existing one to 11.x would be best.
Comment #20
dburiak CreditAttribution: dburiak at ImageX commentedAdded MR to 11.x: https://git.drupalcode.org/issue/drupal-3419621/-/tree/3419621-typeerror...
Please review.
Comment #21
dburiak CreditAttribution: dburiak at ImageX commentedComment #22
smustgrave CreditAttribution: smustgrave at Mobomo 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 CreditAttribution: lpeabody as a volunteer and at Digital Polygon 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 CreditAttribution: dburiak at ImageX commentedComment #25
dburiak CreditAttribution: dburiak at ImageX 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 CreditAttribution: dburiak at ImageX commentedComment #27
smustgrave CreditAttribution: smustgrave at Mobomo 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 CreditAttribution: dburiak at ImageX commentedComment #30
dburiak CreditAttribution: dburiak at ImageX commented@smustgrave the summary is updated. Please review.
Comment #31
dburiak CreditAttribution: dburiak at ImageX commentedComment #32
pameeela CreditAttribution: pameeela at Technocrat commentedI think the IS is OK now.
Comment #33
smustgrave CreditAttribution: smustgrave at Mobomo 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 CreditAttribution: dburiak at ImageX commentedComment #36
dburiak CreditAttribution: dburiak at ImageX 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 CreditAttribution: pameeela at Technocrat 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 CreditAttribution: smustgrave at Mobomo commentedMR just needed a rebase, all green now!
Comment #44
nod_Committed 7e28ed5 and pushed to 11.x. Thanks!