Issue #3614068: Read the image settings the module actually ships (3.0.x)

Backport of the 4.0.x fix (MR !13 (merged), commit 9cd6a4cb) to 3.0.x.

The bug

config/install/layout_builder_kit.settings.yml ships flat keys into the config object layout_builder_kit.settings, but the settings form and both image-uploading components read a different object, layout_builder_kit.image_component, with keys nested under a layout_builder_kit mapping.

Nothing read what the module ships, so on a fresh install the components built their managed_file element with 'file_validate_extensions' => [NULL] — i.e. no file-extension validation at all — until an administrator happened to save the settings form. Reproduced on Drupal 11.4.4:

layout_builder_kit.settings        => {"image_location":"layout_builder_kit","image_extensions":"gif png jpg jpeg webp"}
layout_builder_kit.image_component => []
lbk_image     extensions: array(0 => NULL)
lbk_icon_text extensions: array(0 => NULL)

LBKIconText was doubly wrong: it read a flat image_location from the nested object, so its upload folder ignored the administrator's setting even after the form was saved.

The fix

Everything now uses layout_builder_kit.settings with flat keys:

  • src/Form/LayoutBuilderKitSettingsForm.php
  • src/Plugin/Block/LBKImage/LBKImage.php
  • src/Plugin/Block/LBKIconText/LBKIconText.php

layout_builder_kit_update_10001() copies any administrator-saved values out of the superseded object and deletes it. It skips empty values (a partially populated old object cannot blank a working default) and no-ops when the object does not exist, so it is safe to re-run. The number 10001 deliberately matches 4.0.x, so a site upgrading 3.0.x → 4.0.x does not run the migration twice.

The deprecated layout_builder_kit.image_component schema entry is added here (3.0.x never declared it, so the form was writing an object with no schema) and retained with an explanatory comment: schema must outlive the data it describes, because sites hold that object between deploying the code and running updates.

Beyond the 4.0.x fix

layout_builder_kit.settings was declared type: config_entity on this branch. It is simple config, not a config entity; corrected to config_object (4.0.x already had this).

Tests

The existing tests on 3.0.x were never discovered. Both files ended in Tests.php, and PHPUnit only collects *Test.php, so running the suite by directory returned No tests executed!. Renamed with git mv (classes renamed to match, PSR-4):

  • tests/src/Unit/LayoutBuilderKitTests.php — an empty skeleton with a setUp() and no test methods. Once actually discovered, a non-abstract test class with zero tests errors under some PHPUnit versions, and there is no unit-testable logic here (everything needs the container). Deleted; the new Kernel tests carry the coverage.
  • tests/src/Functional/LayoutBuilderKitUITests.php → LayoutBuilderKitUITest.php (2 tests, 7 assertions, passing).

New Kernel coverage: ImageUploadConfigTest (components + settings form) and ImageConfigUpdateTest (the migration, including the re-run and empty-value cases).

No data providers. This branch declares core_version_requirement: ^10 || ^11. Drupal 10 ships PHPUnit 9, which cannot read PHP attribute metadata such as #[DataProvider], so attribute-driven providers copied from 4.0.x would silently fail to bind on D10. Explicit test methods plus doc-comment @group bind identically under PHPUnit 9, 10 and 11.

Proof the tests run (directory discovery, Drupal 11.4.4 / PHP 8.3.30 / PHPUnit 11.5.56)

Before — phpunit -c . --testdox ../modules/custom/layout_builder_kit/tests:

No tests executed!

After:

Image Config Update   ✔ Administrator values are migrated
                      ✔ No old config leaves defaults intact
                      ✔ Empty values do not overwrite defaults
Image Upload Config   ✔ Installed defaults are readable
                      ✔ Image upload validators use shipped defaults
                      ✔ Icon text upload validators use shipped defaults
                      ✔ Image honours configured values
                      ✔ Icon text honours configured values
                      ✔ Form defaults come from installed config
                      ✔ Form submission writes to settings
Layout Builder Kit UI ✔ Layout builder kit module help
                      ✔ Layout builder kit configuration

Tests: 12, Assertions: 37

End-to-end on a real Drupal 11.4.4 site

Before: lbk_image / lbk_icon_text extensions array(0 => NULL). After: both array(0 => 'gif png jpg jpeg webp'), location public://layout_builder_kit. Update path: seeded the old object with client_uploads / png svg, ran drush updatedb → values migrated, old object deleted, both components then reported public://client_uploads / png svg.


Merges on this project fast-forward, so a Closes #3614068 keyword would not auto-fire; the issue needs to be closed by hand.

Merge request reports

Loading
Loading