You are here

class AccordionMenusBlock in Accordion Menus 8

Same name in this branch
  1. 8 src/Plugin/Derivative/AccordionMenusBlock.php \Drupal\accordion_menus\Plugin\Derivative\AccordionMenusBlock
  2. 8 src/Plugin/Block/AccordionMenusBlock.php \Drupal\accordion_menus\Plugin\Block\AccordionMenusBlock
Same name and namespace in other branches
  1. 8.4 src/Plugin/Derivative/AccordionMenusBlock.php \Drupal\accordion_menus\Plugin\Derivative\AccordionMenusBlock
  2. 8.2 src/Plugin/Derivative/AccordionMenusBlock.php \Drupal\accordion_menus\Plugin\Derivative\AccordionMenusBlock
  3. 8.3 src/Plugin/Derivative/AccordionMenusBlock.php \Drupal\accordion_menus\Plugin\Derivative\AccordionMenusBlock

Provides block plugin definitions for accordion menus.

Hierarchy

Expanded class hierarchy of AccordionMenusBlock

See also

\Drupal\accordion_menus\Plugin\Block\AccordionMenusBlock

File

src/Plugin/Derivative/AccordionMenusBlock.php, line 20
Contains \Drupal\accordion_menus\Plugin\Derivative\AccordionMenusBlock.

Namespace

Drupal\accordion_menus\Plugin\Derivative
View source
class AccordionMenusBlock 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.manager')
      ->getStorage('menu'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {

    // Get menus from accordion configuration.
    $accordion_menus = \Drupal::config('accordion_menus.settings')
      ->get('accordion_menus');
    foreach ($this->menuStorage
      ->loadMultiple() as $menu => $entity) {
      if (in_array($menu, $accordion_menus, true)) {
        $this->derivatives[$menu] = $base_plugin_definition;
        $this->derivatives[$menu]['admin_label'] = t('Accordion ') . $entity
          ->label();
        $this->derivatives[$menu]['config_dependencies']['config'] = [
          $entity
            ->getConfigDependencyName(),
        ];
      }
    }
    return $this->derivatives;
  }

}

Members

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