class SystemMenuBlock

Same name in this branch
  1. 9 core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock
Same name and namespace in other branches
  1. 11.x core/modules/system/src/Plugin/Derivative/SystemMenuBlock.php \Drupal\system\Plugin\Derivative\SystemMenuBlock
  2. 11.x core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock
  3. 10 core/modules/system/src/Plugin/Derivative/SystemMenuBlock.php \Drupal\system\Plugin\Derivative\SystemMenuBlock
  4. 10 core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock
  5. 8.9.x core/modules/system/src/Plugin/Derivative/SystemMenuBlock.php \Drupal\system\Plugin\Derivative\SystemMenuBlock
  6. 8.9.x core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock

Provides block plugin definitions for custom menus.

Hierarchy

  • class \Drupal\system\Plugin\Derivative\SystemMenuBlock implements \Drupal\Core\Plugin\Discovery\ContainerDeriverInterface extends \Drupal\Component\Plugin\Derivative\DeriverBase

Expanded class hierarchy of SystemMenuBlock

See also

\Drupal\system\Plugin\Block\SystemMenuBlock

File

core/modules/system/src/Plugin/Derivative/SystemMenuBlock.php, line 15

Namespace

Drupal\system\Plugin\Derivative
View source
class SystemMenuBlock extends DeriverBase implements ContainerDeriverInterface {
  
  /**
   * The menu storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $menuStorage;
  
  /**
   * Constructs new SystemMenuBlock.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $menu_storage
   *   The menu storage.
   */
  public function __construct(EntityStorageInterface $menu_storage) {
    $this->menuStorage = $menu_storage;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container->get('entity_type.manager')
      ->getStorage('menu'));
  }
  
  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    foreach ($this->menuStorage
      ->loadMultiple() as $menu => $entity) {
      $this->derivatives[$menu] = $base_plugin_definition;
      $this->derivatives[$menu]['admin_label'] = $entity->label();
      $this->derivatives[$menu]['config_dependencies']['config'] = [
        $entity->getConfigDependencyName(),
      ];
    }
    return $this->derivatives;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.