Problem/Motivation

On the latest release version (1.0.0.0-alpha5), I'm often getting these notices:

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).

A full stacktrace, if it's useful. But I get these several times, at different instances:

Drupal\bootstrap_styles\Plugin\BootstrapStyles\Style\BackgroundColor->build(Array, Array, 'blb_container_wrapper') (Line: 277)
Drupal\bootstrap_styles\StylesGroup\StylesGroupManager->buildStyles(Array, Array, 'blb_container_wrapper') (Line: 131)
Drupal\bootstrap_layout_builder\Plugin\Layout\BootstrapLayout->build(Array) (Line: 91)
Drupal\layout_builder\Section->toRenderArray(Array) (Line: 317)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildSections(Object) (Line: 276)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 351)
Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 24)
Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 293)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 250)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 100)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Unfortunately, I'm not exactly sure what is causing it (and therefore, I don't know how to reproduce it). I am using Display Suite, and some of my content types have display modes that are using a bootstrap layout. I'm not sure if that could be the case.

It seems to cause the $storage variable to be an empty array when it reaches the BackgroundColor->build() method for some reason.

Proposed resolution

My band-aid resolution for now is just to check if $storage is an empty array and to return early if that is the case. It doesn't break any existing functionality.

Remaining tasks

  • Figure out why the $storage variable is empty.
  • Validate the $storage variable before continuining with execution.

Comments

gueguerreiro created an issue. See original summary.

gueguerreiro’s picture

Assigned: gueguerreiro » Unassigned
Status: Active » Needs review
StatusFileSize
new1.62 KB

This is the patch I'm using the avoid the notice warning, in case this is happening to anyone else. It won't break functionality, but if the $storage truly isn't supposed to ever be empty, the real fix should be figuring out why it is empty in the first place. Otherwise, I think is good to commit.

Waiting for a maintainer to weight in.

gueguerreiro’s picture

StatusFileSize
new1.63 KB

Slightly updated patch. BackgroundColor::buildStyleFormElements() should always return an array, not void.

mahmoud-zayed’s picture

Hi Miguel,

Thanks for the patch and I will review and update you soon!

Regards,
Mahmoud

sahil432’s picture

Hi mahmoud,

i am also getting same randomly not sure root cause

Notice: Undefined index: background in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Warning: count(): Parameter must be an array or an object that implements Countable in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Notice: Undefined index: background_color in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/BackgroundColor.php on line 57

Notice: Undefined index: background in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Warning: count(): Parameter must be an array or an object that implements Countable in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Notice: Undefined index: spacing in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Warning: count(): Parameter must be an array or an object that implements Countable in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Notice: Undefined index: padding in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Padding.php on line 57

Notice: Undefined index: spacing in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Warning: count(): Parameter must be an array or an object that implements Countable in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Notice: Undefined index: margin in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Margin.php on line 57

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Warning: count(): Parameter must be an array or an object that implements Countable in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 249

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 265

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 281

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 298

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 314

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 330

Notice: Undefined index: border indocroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 298

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 314

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 330

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 298

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 314

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 330

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 298

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 314

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 330

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 369

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 369

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 396

Notice: Undefined index: border in docroot/modules/contrib/bootstrap_styles/src/Plugin/BootstrapStyles/Style/Border.php on line 396

Notice: Undefined index: animation in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

Warning: count(): Parameter must be an array or an object that implements Countable in docroot/modules/contrib/bootstrap_styles/src/StylesGroup/StylesGroupManager.php on line 179

gueguerreiro’s picture

Status: Needs review » Needs work

Hmm, my patch only addresses the Background specifically, but it appears this is happening with more components. I'll set it to NW. I'm glad that at least I'm not the only one getting this. I'll see if I have some free time this weekend to try and replicate this behavior on a clean project.

Are you also using any of the following modules along with bootstrap_styles @sahil432?

  • ds
  • bootstrap_layout_builder
sahil432’s picture

@gueguerreiro
Drupal Core :- 8.8.8
• Layout Builder, Layout Discovery
• Bootstrap Layout Builder(2.0.0-alpha6), Bootstrap Styles
• Layout Builder Asymmetric translation
• Layout Builder Blocks, Layout Builder Restrictions

gueguerreiro’s picture

Status: Needs work » Closed (duplicate)

After looking more carefully at the issue queue, this seems to be a duplicate of #3169853: 1x -> 2x (Upgrade Issue). There's already a patch there that was commited that should help reduce the logs you're getting @sahil432, but it is currently only on the development branch, not the default alpha5 branch that the bootstrap_layout_builder requires.

The issue there is still on NW, so I'll focus my attention to it and close this one.

gueguerreiro’s picture

gueguerreiro’s picture

@sahil432, I believe I found the root cause of your undefined index errors, it was unrelated to the previous one I linked. I opened #3173467: Always default to null value for $storage array keys on buildStyleFormElements() methods and created a patch. See if that helps you.