Problem/Motivation

When placing some blocks into the page we are facing AJAX error where the block is not added.
The error is
Undefined array key "background_video" in <b>/var/www/web/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/BackgroundMedia.php

Comments

carolpettirossi created an issue. See original summary.

olegrymar’s picture

A patch has been added to fix this issue.

olegrymar’s picture

olegrymar’s picture

Status: Active » Needs review
jandewit6’s picture

Also here I am running into this issue. making it impossible to update layouts as all added sections are 'saved'.
After applying the patch, still the same issue. Adaptations are saved according to front end, but on re-opening the layout, the newly added sections disappeared.

After applying the patch, I am getting a OutOfBoundsException: Invalid delta "0" in Drupal\layout_builder\Field\LayoutSectionItemList->getSection() (line 42 of ***/public_html/core/modules/layout_builder/src/SectionListTrait.php).

iamweird’s picture

Probably this issue is obsolete since #3388219: Fix InvalidArgumentException: Invalid ID provided for the media entity already changed same lines as patch from #2. Can anyone provide steps to reproduce this issue?

chike’s picture

I can still reproduce this issue on Bootstrap Styles 1.2.2. The error occurs when trying to save a block in Layout Builder when the background video media bundle is not configured in the Bootstrap Styles settings.

The patch from #2 no longer applies to the current codebase. I've created an updated patch that addresses the root cause:

The issue is in the submitStyleFormElements() method at line 364. The method attempts to access $group_elements['background_video'] without checking if it exists. The `background_video` field is only added to the form conditionally (line 261) - only when a video media bundle is configured. When this configuration is missing, the field doesn't exist in the form, causing the undefined array key warning.

This patch adds:

  • An isset() check before accessing `background_video`
  • Null coalescing operators for all `background_options` fields to prevent similar issues
  • Defensive fallbacks for `background_image` as well

The patch works for me on Drupal 11.3.1 with Bootstrap Styles 1.2.2.

chike’s picture

Version: 1.1.0 » 1.2.x-dev
bbu23’s picture

On website installed with minimal recipe, the expected media types won't be available. The module should not assume the presence of an optional media entity type.

In the latest version of the module at the time of writing (1.2.3), on a website using minimal plus only the media image bundle installed, the configuration form is broken and the layout builder is almost impossible to use. This is because the module expects the local video media bundle to exist.

After installing the local_video_media_type recipe from core, and navigating to the global configuration form, the media field is correctly populated, so resaving the settings also fixes the crashes in the layout builder.

Proposed resolution: Make the configuration dynamic and not dependant on some core types that can be missing when not using the standard recipe. Not everybody wants to have a local video media type installed, or maybe others prefer to set up their own media types with custom IDs. The module should take in consideration the minimal installation first.