Initial class save causes array_merge error

Created on 4 March 2023, over 1 year ago
Updated 31 May 2024, 27 days ago
  • Install module from scratch
  • Enable autocomplete in config
  • Save block with classes

Results in error

Uncaught PHP Exception TypeError: "array_merge(): Argument #1 must be of type array, null given" at /web/modules/contrib/block_class/src/Service/BlockClassHelperService.php line 202
πŸ’¬ Support request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia VladimirAus Brisbane, Australia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @VladimirAus
  • @vladimiraus opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia VladimirAus Brisbane, Australia

    Good to go!

  • Status changed to RTBC about 1 year ago
  • πŸ‡ΊπŸ‡Έ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 27 days ago
  • πŸ‡«πŸ‡·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 expected

    Tested 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 not null.

    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: 🟒

    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.

Production build 0.69.0 2024