You are here

class TBMegaMenuBlock in The Better Mega Menu 2.x

Same name in this branch
  1. 2.x src/Plugin/Derivative/TBMegaMenuBlock.php \Drupal\tb_megamenu\Plugin\Derivative\TBMegaMenuBlock
  2. 2.x src/Plugin/Block/TBMegaMenuBlock.php \Drupal\tb_megamenu\Plugin\Block\TBMegaMenuBlock
Same name and namespace in other branches
  1. 8 src/Plugin/Derivative/TBMegaMenuBlock.php \Drupal\tb_megamenu\Plugin\Derivative\TBMegaMenuBlock

Provides blocks which belong to TB Mega Menu.

Hierarchy

Expanded class hierarchy of TBMegaMenuBlock

File

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

Namespace

Drupal\tb_megamenu\Plugin\Derivative
View source
class TBMegaMenuBlock extends DeriverBase implements ContainerDeriverInterface {

  /**
   * Config factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Entity type manager.
   *
   * @var \Drupal\core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * TBMegaMenuBlock constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   Config factory interface.
   */
  public function __construct(ConfigFactoryInterface $configFactory, EntityTypeManagerInterface $entityTypeManager) {
    $this->configFactory = $configFactory;
    $this->entityTypeManager = $entityTypeManager;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $menus = $this->entityTypeManager
      ->getStorage('menu')
      ->loadMultiple();
    asort($menus);
    foreach ($this->configFactory
      ->listAll('tb_megamenu.menu_config.') as $index_id) {
      $info = $this->configFactory
        ->get($index_id);
      $menu = $info
        ->get('menu');
      if (isset($menus[$menu])) {
        $this->derivatives[$menu] = $base_plugin_definition;
        $this->derivatives[$menu]['admin_label'] = $menus[$menu]
          ->label();
      }
    }
    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
TBMegaMenuBlock::$configFactory protected property Config factory service.
TBMegaMenuBlock::$entityTypeManager protected property Entity type manager.
TBMegaMenuBlock::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
TBMegaMenuBlock::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
TBMegaMenuBlock::__construct public function TBMegaMenuBlock constructor.