You are here

GroupMenuBlock.php in Group Content Menu 8

File

src/Plugin/Derivative/GroupMenuBlock.php
View source
<?php

namespace Drupal\group_content_menu\Plugin\Derivative;

use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides block plugin definitions for custom menus.
 */
class GroupMenuBlock 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('group_content_menu_type'));
  }

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

}

Classes

Namesort descending Description
GroupMenuBlock Provides block plugin definitions for custom menus.