Closed (fixed)
Project:
Block Class
Version:
4.0.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
4 Mar 2023 at 16:02 UTC
Updated:
22 Nov 2025 at 00:14 UTC
Jump to comment: Most recent
Comments
Comment #3
vladimirausGood to go!
Comment #4
chris matthews commentedComment #5
chris matthews commentedManually tested by:
Installing drupal 10.0.9
Installing block_class (dev-2.0.x b1f185f)
(At /admin/config/content/block-class/settings, 'Enable auto-complete' was already enabled by default)
Adding a class to a block resulted in:
TypeError: array_merge(): Argument #1 must be of type array, null given in array_merge() (line 193 of /code/web/modules/contrib/block_class/src/Service/BlockClassHelperService.php).Repeating above but with the patch applied did not throw this error so confidently setting to RTBC.
Comment #6
dydave commentedThanks everyone for creating this ticket and your code contributions, it's greatly appreciated!
I've taken a quick look at this issue and tried repeating the steps described in the IS and at #5 but unfortunately I was unable to reproduce the problem and prompt the PHP error message:
✅ No crash: Everything worked fine/as expected
Tested with:
Step 1: Install module block_class from scratch (no prior config):
As you can see
block_classes_stored: { }is an array, so it seems it "should" have an empty array[]as its default value and notnull.Additionally, is seems auto-complete is enabled by default as well:
enable_auto_complete: true.See current:
block_class.settings.ymlhttps://git.drupalcode.org/project/block_class/-/blob/e03fb6a61296eb8ae5...
Step 2: Browse to "Main page content" (
system_main_block) edit form:/admin/structure/block/manage/olivero_contentStep 3: Add a class in autocomplete field "CSS class", for example: 'testingBC1', then save.
I'm not sure if I'm missing anything here, but with a fresh
'drupal/block_class:2.0.x-dev@dev'module install I was not able to reproduce the error.Could someone please take another look at this issue and let us know if the problem is still affecting the latest 2.0.x DEV code base?
For reference, it seems the default value of the
block_classes_storedconfig was updated in #3338774: Storing block_classes_stored as a string value leads to poor developer experience.Lastly, I'd like to point out the steps outlined above should actually be the same ones executed in module's Functional tests for the Create ("add") block form:
/admin/structure/block/add/system_main_block/olivero.which all seem to be passing at the moment: 🟢
Code in test class:
https://git.drupalcode.org/project/block_class/-/blob/e03fb6a61296eb8ae5...
We would greatly appreciate if anyone could help confirming the problem in this ticket has been resolved in current DEV, or if it is still active, in which case, more contextual information would be very helpful.
Thanks in advance for your tests, reporting, comments and feedback.
Comment #7
vladimiraus@DYdave which php version are you testing against?
Should be 8.2+
Comment #8
dydave commentedThanks a lot Vladimir (@VladimirAus) and sorry for the late reply.
OK, I've given this another round of tests and still no luck reproducing the issue 😭
Fresh Drupal 11 install on a DDEV stack:
Enabled via drush, same config as above at #6 (DEFAULT):
PHP 8.3 :
Same steps followed as above at #6:
No error, the form was submitted properly, value saved and block class displayed....
Additionally, I'd like to point out 2.0.x has
OPT_IN_TEST_MAX_PHP: 1, so all the functional tests should be running for PHP 8.3, see the following pipeline:https://git.drupalcode.org/issue/block_class-3345203/-/pipelines/249232
MAX PHP 8.3 on D10.3.3-dev job : https://git.drupalcode.org/issue/block_class-3345203/-/jobs/2396338
All passing 🟢
Vladimir (@VladimirAus), I really don't know what else I could do here ...
I would really like to help testing this and I've already spent quite some time trying to reproduce the issue ...
On top of that, I'm rather surprised the problem isn't getting more traction, in the sense: We're not getting more reports or feedback on this, when the problem should be pretty critical and jump out to users on first use of the module/class config.
If you have any suggestions on how I could be reproducing this, I'd be very grateful!
Currently, I'm on a DDEV stack, fresh D10 or D11 install, PHP 8.3, block_class 2.0.x HEAD
Thanks in advance !
Comment #9
vladimirausHere's what I have on
After dragging blocks around and saving blocks:
If you cannot reploduce it on the fresh one, it might be bad update procedure from Drupal 9.
Comment #12
vladimirausComment #13
jannakha commentedMR#12 doesn't work in my case where configuration is not stored as expected:
bloc_class_settings.yml contains:
block_classes_stored: '{"social-icons-inline":"social-icons-inline","container":"container","block-below":"block-below","popup-services-browser":"popup-services-browser","popup-buildings-browser":"popup-buildings-browser","pull-right":"pull-right","block-blog-tags":"block-blog-tags","block-banner-banner":"block-banner-banner","block-solutions-back-button":"block-solutions-back-button","col-md-6":"col-md-6","col-lg-60":"col-lg-60","clear-xs":"clear-xs","clear-sm":"clear-sm","floating-links-2":"floating-links-2","padding-large-md-right":"padding-large-md-right","padding-none-xs-right":"padding-none-xs-right","padding-none-xs-left":"padding-none-xs-left","block-small-margin":"block-small-margin","search-form-block":"search-form-block","col-xs-5":"col-xs-5","col-sm-3":"col-sm-3","col-lg-20":"col-lg-20","padding-lg-right":"padding-lg-right","view-keyword-search-filters":"view-keyword-search-filters","block-covid-19-message":"block-covid-19-message","block-front-cta":"block-front-cta","col-sm-5":"col-sm-5","col-md-4":"col-md-4","block-360-solutions-video-popup":"block-360-solutions-video-popup","destroy-on-close":"destroy-on-close","":"","request-quote-link":"request-quote-link","d-md-inline-block":"d-md-inline-block","w-md-50":"w-md-50"}'is my config old or wrong?
Comment #14
jannakha commentedupdb didn't run properly update hook block_class_update_20017() which updates config structure
Comment #15
stewestFYI - this is similar https://www.drupal.org/project/block_class/issues/3467450 and the patch here worked for me https://git.drupalcode.org/project/block_class/-/merge_requests/52.diff
Comment #16
simsimsim101 commentedIs this issue has been resolved? Whenever I try to modify a block (title, description, position in the layout, etc..) I get the same error from Mr#9 :
TypeError: array_merge(): Argument #1 must be of type array, string given in array_merge() (line 202 of modules/contrib/block_class/src/Service/BlockClassHelperService.php).
I tried the command "drush cget block_class.settings" and the block_classes_stored does not contain any array's but is instead kept in string:
block_classes_stored: '{"col-sm-4":"col-sm-4","col-md-3":"col-md-3","col-sm-offset-2":"col-sm-offset-2","col-md-offset-4":"col-md-offset-4","col-lg-offset-5":"col-lg-offset-5","col-sm-6":"col-sm-6","col-md-5":"col-md-5","col-lg-4":"col-lg-4","col-md-12":"col-md-12","col-sm-7col-lg-6":"col-sm-7col-lg-6","col-sm-3":"col-sm-3","col-lg-offset-3":"col-lg-offset-3","col-sm-12":"col-sm-12"}'
It seems like the " $current_block_classes = explode(' ', $block_classes ?? ''); " doesn't convert the String value to an array correctly...
Here's the solutions that I tried by following this comment thread:
-> Change the line 196 of BlockClassHelperService.php to " $block_classes_stored = $config->get('block_classes_stored') ?? [];"
-> The Commands "drush cr" + "drush updb".
-> Starting the local environment to a clean build (started over from scratch with 0 file modified from the origin).
Did anyone find a solution to the error from Mr#9 ?
Comment #17
simsimsim101 commentedComment #18
liam morlandI have seen this on sites that did not have any outstanding update hooks. It was fixed by a cache clear. This is probably a bug that ought to be fixed.
Comment #19
hanan alasariMR#12 worked for me, thank you!!
Comment #20
ronraney commentedI'm seeing this every time I save the Block Layout page.
Comment #21
ronraney commentedI have the patch installed. I'm now seeing this when I run composer update or install.
Comment #22
rcodinaThis issue is still present in version 4.0.1. Applying the patch from MR#12 worked for me as well, same as for user #19. Thanks!
@ronraney This occurs because you have a Git sub-repository — it usually happens when a dev version is required via Composer. Removing the module manually and reinstalling a tagged release should resolve it.
Comment #23
dydave commentedOK Roger (@rcodina) 👌
I'm going to accept patch from MR !12 👍
I'll get this merged later today, which should be included in
4.0.2.Thanks again Roger for reporting back on this issue.
Comment #24
dydave commentedUpdated version to current 4.0.x development branch.
Comment #26
dydave commentedQuick follow-up on this issue:
It's been active for a long time, received reasonable testing feedback, reviews and the changes are so small/minor, without much impact to be expected on the module, that it would be a shame not to just get them in the module 😅
Sure that's adding code that may not be absolutely necessary (initialization of config, schema, and such)... there might still be edge cases, depending on projects, where this issue might occur...
Since it should do no harm to the project to add a few additional init checks here and there, I went ahead and merged the changes above at #25. 🥳
This patch should be released very shortly with the next stable, which should hopefully prevent this issue from occurring again in the future.
Feel free to let us know if you have any questions or concerns on any aspects of the latest code changes or the module in general, we would surely be glad to hear your feedback. 😊
Thanks in advance!