- Issue created by @VladimirAus
- Merge request !12Issue #3345981: Initial class save causes array_merge error β (Open) created by VladimirAus
- Status changed to Needs review
over 1 year ago 4:05pm 4 March 2023 - Status changed to RTBC
over 1 year ago 7:26pm 29 May 2023 - πΊπΈUnited States Chris Matthews
Manually 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.
- Status changed to Needs review
6 months ago 10:51pm 31 May 2024 - π«π·France dydave
Thanks 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 expectedTested with:
- drupal/core: 10.2.5
- drupal/block_class: 'dev-2.0.x:e03fb6a61296eb8ae595bfc8298e33e633a57610'
Step 1: Install module block_class from scratch (no prior config):> drush en block_class [success] Successfully enabled: block_class > drush cget block_class.settings _core: default_config_hash: XEpuHrBp3DELKxVx0tmwE6CS7NSIKXu4F6QhT_vwqd0 block_classes_stored: { } default_case: standard enable_attributes: true enable_auto_complete: true enable_id_replacement: true enable_special_chars: false field_type: multiple_textfields filter_html_clean_css_identifier: '' items_per_page: 50 qty_attributes_per_block: 10 qty_classes_per_block: 10 maxlength_attributes: 255 maxlength_block_class_field: 255 maxlength_id: 255 weight_attributes: 0 weight_class: 0 weight_id: 0
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.yml
https://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_content
Step 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_stored
config was updated in β¨ Storing block_classes_stored as a string value leads to poor developer experience Fixed .
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: π’- 2.0.x build at e03fb6a: https://git.drupalcode.org/project/block_class/-/pipelines/186710
- PHPUnit job, passed: https://git.drupalcode.org/project/block_class/-/jobs/1734345
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.
- π¦πΊAustralia VladimirAus Brisbane, Australia
@DYdave which php version are you testing against?
Should be 8.2+ - π«π·France dydave
Thanks 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:
- Drupal version : 11.0-dev
- Block Class: 2.0.x-dev (from HEAD)
Enabled via drush, same config as above at #6 (DEFAULT):
PHP 8.3 :/var/www/html$ php -v PHP 8.3.8 (cli) (built: Jun 8 2024 21:31:55) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.8, Copyright (c) Zend Technologies with Zend OPcache v8.3.8, Copyright (c), by Zend Technologies
Same steps followed as above at #6:
Step 2: Browse to "Main page content" (
system_main_block
) edit form:
/admin/structure/block/manage/olivero_content
Step 3: Add a class in autocomplete field "CSS class", for example: 'testingBC1', then save.
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/2396338All 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 !
- Status changed to Needs work
3 months ago 1:13am 18 August 2024 - π¦πΊAustralia VladimirAus Brisbane, Australia
Here's what I have on
- Block Class 2.0.12
- Drupal 10.3.2
- PHP 8.3
After dragging blocks around and saving blocks:
The website encountered an unexpected error. Try again later. 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). Drupal\block_class\Service\BlockClassHelperService->blockClassPreSave(Object) (Line: 107) block_class_block_presave(Object) call_user_func_array(Object, Array) (Line: 416) Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'block_class') (Line: 395) Drupal\Core\Extension\ModuleHandler->invokeAllWith('block_presave', Object) (Line: 415) Drupal\Core\Extension\ModuleHandler->invokeAll('block_presave', Array) (Line: 341) Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('presave', Object) (Line: 529) Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 483) Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 257) Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 354) Drupal\Core\Entity\EntityBase->save() (Line: 614) Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 392) Drupal\block\BlockListBuilder->submitForm(Array, Object)
If you cannot reploduce it on the fresh one, it might be bad update procedure from Drupal 9.
- π¦πΊAustralia VladimirAus Brisbane, Australia
vladimiraus β changed the visibility of the branch 3345981-initial-class-save to hidden.
- π¦πΊAustralia VladimirAus Brisbane, Australia
vladimiraus β changed the visibility of the branch 3345981-initial-class-save to active.
- Status changed to Needs review
3 months ago 1:16am 18 August 2024 - Status changed to Needs work
3 months ago 12:52pm 20 August 2024 - π¦πΊAustralia jannakha Brisbane!
MR#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?
- Status changed to Closed: outdated
3 months ago 1:16pm 20 August 2024 - π¦πΊAustralia jannakha Brisbane!
updb didn't run properly update hook block_class_update_20017() which updates config structure
- π³πΏNew Zealand stewest Wellington
FYI - this is similar https://www.drupal.org/project/block_class/issues/3467450 π Failsafe conversion of block_classes_stored RTBC and the patch here worked for me https://git.drupalcode.org/project/block_class/-/merge_requests/52.diff