diff --git a/src/Plugin/Block/MenuBlock.php b/src/Plugin/Block/MenuBlock.php index da0ff0b..f4afbb8 100644 --- a/src/Plugin/Block/MenuBlock.php +++ b/src/Plugin/Block/MenuBlock.php @@ -2,12 +2,10 @@ namespace Drupal\menu_block\Plugin\Block; -use Drupal\Core\Access\AccessResult; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Link; use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Render\Markup; -use Drupal\Core\Session\AccountInterface; use Drupal\system\Entity\Menu; use Drupal\system\Plugin\Block\SystemMenuBlock; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -327,6 +325,11 @@ class MenuBlock extends SystemMenuBlock { $tree = $this->menuTree->transform($tree, $manipulators); $build = $this->menuTree->build($tree); + // There are no menu items to display, so don't render the menu. + if (empty($build['#items'])) { + return []; + } + $label = $this->getBlockLabel() ?: $this->label(); // Set the block's #title (label) to the dynamic value. $build['#title'] = [