Care for unexposed keys in my_pattern.ui_patterns.yml

Created on 4 June 2023, about 1 year ago
Updated 10 November 2023, 8 months ago

Support patterns that do not expose regions

Problem/Motivation

If a ui_pattern plugin does not expose fields, ComponentBlock::getConfiguration()['variables'] with this pattern gives an empty array. In ComponentBlock::build() there's no empty(array) check for this array, thus throws an Error.

Steps to reproduce

- Create a ui_pattern but do not expose the fields β†’ section in the plugin-definition file myPattern.ui_pattern.yml
- Add myPattern in Layout_Builder
-> you get
Warning: foreach() argument must be of type array|object, null given in Drupal\component_blocks\Plugin\Block\ComponentBlock->build() (line 196 of modules/contrib/component_blocks/src/Plugin/Block/ComponentBlock.php).

Proposed resolution

Check ComponentBlock::getConfiguration()['variables'] with empty(array) before evaluating the foreach loop

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany TomSaw Essen

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

Comments & Activities

Production build 0.69.0 2024