Undefined index: attributes in Drupal\bootstrap\Plugin\Preprocess\Menu

Created on 26 July 2022, about 2 years ago
Updated 11 September 2023, about 1 year ago

Sorry to not provide detailed “steps to reproduce”, but I’m in the middle of a complicated (for me) site build and got the following:

Notice: Undefined index: attributes in Drupal\bootstrap\Plugin\Preprocess\Menu->convertAttributes() (line 36 of themes\contrib\bootstrap\src\Plugin\Preprocess\Menu.php).
Drupal\bootstrap\Plugin\Preprocess\Menu->convertAttributes(Array) (Line: 23)
Drupal\bootstrap\Plugin\Preprocess\Menu->preprocessVariables(Object) (Line: 53)
Drupal\bootstrap\Plugin\Preprocess\PreprocessBase->preprocess(Array, 'menu', Array) (Line: 1441)
Drupal\bootstrap\Bootstrap::preprocess(Array, 'menu', Array) (Line: 118)
bootstrap_preprocess(Array, 'menu', Array)
call_user_func_array('bootstrap_preprocess', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('menu', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 94)
template_preprocess_toolbar(Array, 'toolbar', Array)
call_user_func_array('template_preprocess_toolbar', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('toolbar', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 117)
__TwigTemplate_5ca2a3e6b6c9c411839d8224654db4c854537f9c6273c49236b17332b4d4a009->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/contrib/dxpr_theme/templates/html.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 162)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 163)
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: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
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: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

To make matters worse, I’m actually using DXPR Theme on the frontend which depends on Bootstrap, plus this coincides somewhat with installing Shortcut Menu . The warning repeats 12 times on the pages where it appears, and I see no relation between the pages it appears on and the ones it doesn’t. Happy to help diagnose in any way I can.

🐛 Bug report
Status

Fixed

Version

3.25

Component

Code

Created by

🇭🇺Hungary Grabby

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia Stefan Lehmann

    I had a link render array in the theme I'm upgrading like this:

    $home_link = [
            'title' => 'Home',
            'url' => \Drupal\Core\Url::fromRoute('<front>'),
          ];
    

    I had to update to this to get rid of the notice:

    $home_link = [
            'title' => 'Home',
            'url' => \Drupal\Core\Url::fromRoute('<front>'),
            'attributes' => [],
          ];
    

    I added a small patch in case you think this should be handled by Boostrap. I have no opinions about that, but it doesn't seem to happen to a lot of people.

    • shelane committed 2856bc1c on 8.x-3.x
      Issue #3299961 by Stefan Lehmann, Grabby: Undefined index: attributes in...
  • Status changed to Fixed about 1 year ago
  • 🇺🇸United States shelane

    Thank you. It seems a reasonable check to make. I did streamline it a bit to the same if statement though.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024