Problem/Motivation

This is related to #3172360-7: Notice: Undefined index: background in Drupal\bootstrap_styles\Plugin\BootstrapStyles\Style\BackgroundColor->build() (line 90 of modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/BackgroundColor.php).

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.

Comments

gueguerreiro created an issue. See original summary.

gueguerreiro’s picture

Assigned: gueguerreiro » Unassigned
Status: Active » Needs review
StatusFileSize
new6.68 KB

Here'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.

  • mahmoud-zayed committed ccb7f3c on 1.0.x
    Issue #3173467 by gueguerreiro: Always default to null value for  array...
mahmoud-zayed’s picture

Status: Needs review » Fixed

Hi Miguel,

Thaks for the patch and for well-documented ticket description!

Regards,
Mahmoud

mahmoud-zayed’s picture

Status: Fixed » Closed (fixed)
aaronchristian’s picture