You are here

class UltimenuBlock in Ultimenu 8

Same name in this branch
  1. 8 src/Plugin/Derivative/UltimenuBlock.php \Drupal\ultimenu\Plugin\Derivative\UltimenuBlock
  2. 8 src/Plugin/Block/UltimenuBlock.php \Drupal\ultimenu\Plugin\Block\UltimenuBlock
Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/UltimenuBlock.php \Drupal\ultimenu\Plugin\Derivative\UltimenuBlock

Provides block plugin definitions for Ultimenu.

Hierarchy

Expanded class hierarchy of UltimenuBlock

See also

\Drupal\ultimenu\Plugin\Block\UltimenuBlock

File

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

Namespace

Drupal\ultimenu\Plugin\Derivative
View source
class UltimenuBlock extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The Plugin service.
   *
   * @var \Drupal\ultimenu\UltimenuManagerInterface
   */
  protected $ultimenuManager;

  /**
   * Constructs a new UltimenuBlock.
   *
   * @param \Drupal\ultimenu\UltimenuManagerInterface $ultimenu_manager
   *   The ultimenu manager.
   */
  public function __construct(UltimenuManagerInterface $ultimenu_manager) {
    $this->ultimenuManager = $ultimenu_manager;
  }

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

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

    // Provide a block plugin definition for each ultimenu.
    foreach ($this->ultimenuManager
      ->getUltimenuBlocks() as $key => $name) {
      $menu_key = 'ultimenu-' . $key;
      $this->derivatives[$menu_key] = $base_plugin_definition;
      $this->derivatives[$menu_key]['admin_label'] = t("Ultimenu: @name", array(
        '@name' => $name,
      ));
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

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
UltimenuBlock::$ultimenuManager protected property The Plugin service.
UltimenuBlock::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
UltimenuBlock::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
UltimenuBlock::__construct public function Constructs a new UltimenuBlock.