You are here

class DomainMenuAccessMenuBlock in Domain Menu Access 8

Same name in this branch
  1. 8 src/Plugin/Derivative/DomainMenuAccessMenuBlock.php \Drupal\domain_menu_access\Plugin\Derivative\DomainMenuAccessMenuBlock
  2. 8 src/Plugin/Block/DomainMenuAccessMenuBlock.php \Drupal\domain_menu_access\Plugin\Block\DomainMenuAccessMenuBlock

Provides block plugin definitions for domain access menus.

Hierarchy

Expanded class hierarchy of DomainMenuAccessMenuBlock

See also

\Drupal\domain_access\Plugin\Block\DomainMenuAccessMenuBlock

File

src/Plugin/Derivative/DomainMenuAccessMenuBlock.php, line 15

Namespace

Drupal\domain_menu_access\Plugin\Derivative
View source
class DomainMenuAccessMenuBlock extends SystemMenuBlock {

  /**
   * Domain settings.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;

  /**
   * Constructs new SystemMenuBlock.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $menu_storage
   *   The menu storage.
   * @param \Drupal\Core\Config\ImmutableConfig $config
   *   Domain access settings.
   */
  public function __construct(EntityStorageInterface $menu_storage, ImmutableConfig $config) {
    parent::__construct($menu_storage);
    $this->config = $config;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('entity.manager')
      ->getStorage('menu'), $container
      ->get('config.factory')
      ->get('domain_menu_access.settings'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $menu_enabled = $this->config
      ->get('menu_enabled');
    foreach ($this->menuStorage
      ->loadMultiple() as $menu => $entity) {
      if (in_array($menu, $menu_enabled)) {
        $this->derivatives[$menu] = $base_plugin_definition;
        $this->derivatives[$menu]['admin_label'] = $entity
          ->label();
        $this->derivatives[$menu]['config_dependencies']['config'] = [
          $entity
            ->getConfigDependencyName(),
        ];
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
DomainMenuAccessMenuBlock::$config protected property Domain settings.
DomainMenuAccessMenuBlock::create public static function Creates a new class instance. Overrides SystemMenuBlock::create
DomainMenuAccessMenuBlock::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides SystemMenuBlock::getDerivativeDefinitions
DomainMenuAccessMenuBlock::__construct public function Constructs new SystemMenuBlock. Overrides SystemMenuBlock::__construct
SystemMenuBlock::$menuStorage protected property The menu storage.