diff -u b/menu_item_extras.module b/menu_item_extras.module --- b/menu_item_extras.module +++ b/menu_item_extras.module @@ -156,14 +156,16 @@ $variables['content']['#theme'] = 'menu'; // Pass region name to the suggestions_menu_alter for // the region suggestion. - if (isset($variables['elements']['#id'])) { + if (!empty($variables['elements']['#id'])) { /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $block_storage */ $block_storage = \Drupal::entityTypeManager() ->getStorage('block'); /** @var \Drupal\block\BlockInterface $block */ $block = $block_storage->load($variables['elements']['#id']); - $variables['content']['#attributes']['data-region'] = $block->getRegion(); - }; + if (!empty($block)) { + $variables['content']['#attributes']['data-region'] = $block->getRegion(); + } + } } }