Problem/Motivation
When initially creating a section with layout builder, using a layout_builder_bootstrap layout, the $storage array will be completely empty. But all the buildStyleFormElements() for the various style plugins will still be executed, and they will only be populated once we run through submitStylesFormElements (when we save the layout).
In short this means that there is an initial cycle where it will run through the buildStyleFormElements() while the $storage array is always empty. So those methods should be prepared for that.
On some of them, like BackgroundMedia:
'#default_value' => $storage['background_media']['image']['media_id'] ?? NULL,
... and
'#default_value' => $storage['background_media']['video']['media_id'] ?? NULL,
And Background:
'#default_value' => $storage['background']['background_type'] ?? 'color',
We're already defaulting to a NULL value, but on all the other remaining style plugins we're not.
This makes it so that, when we initally attempt to add a new Bootstrap Layout, and we go to our logs, we'll have several of logs similar to these:
Notice: Undefined index: margin in Drupal\bootstrap_styles\Plugin\BootstrapStyles\Style\Margin->buildStyleFormElements() (line 57 of /app/web/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Margin.php)
Notice: Undefined index: scroll_effects in Drupal\bootstrap_styles\Plugin\BootstrapStyles\Style\ScrollEffects->buildStyleFormElements() (line 93 of /app/web/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/ScrollEffects.php)
Notice: Undefined index: padding in Drupal\bootstrap_styles\Plugin\BootstrapStyles\Style\Padding->buildStyleFormElements() (line 57 of /app/web/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Padding.php)
Since these only happen when we do our Layout Builder Ajax calls, they don't seem to show on the Drupal messages after we save the layout. However, they do still clog up the logs quite a bit, especially if you're managing a lot of content.
Steps to reproduce
- Install bootstrap_layout_builder (Which already depends on this module).
- Try to edit a layout for any given content.
- Click to add a section, and pick a Bootstrap layout.
- Go check the logs.
Proposed resolution
Always attempt to validate if the $storage values we're using are set, and default to NULL if not.
Remaining tasks
Always attempt to validate if the $storage values we're using are set, and default to NULL if not.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | default_null_values-3173467-2.patch | 6.68 KB | gueguerreiro |
Comments
Comment #2
gueguerreiroHere's a patch for that. The undefined index notices are gone now 😁 The only one left is a background one, but it's not related to this. See #3169853: 1x -> 2x (Upgrade Issue), there's a patch for that one there.
Comment #4
mahmoud-zayed commentedHi Miguel,
Thaks for the patch and for well-documented ticket description!
Regards,
Mahmoud
Comment #5
mahmoud-zayed commentedComment #6
aaronchristian commentedRelated: https://www.drupal.org/project/bootstrap_styles/issues/3194272