You are here

class MenuLinks in Event 8

Provides a default implementation for menu link plugins.

Hierarchy

Expanded class hierarchy of MenuLinks

1 string reference to 'MenuLinks'
event.links.menu.yml in ./event.links.menu.yml
event.links.menu.yml

File

src/Plugin/Derivative/MenuLinks.php, line 17

Namespace

Drupal\event\Plugin\Derivative
View source
class MenuLinks extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;
  const MAX_BUNDLE_NUMBER = 10;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The route provider.
   *
   * @var \Drupal\Core\Routing\RouteProviderInterface
   */
  protected $routeProvider;

  /**
   * The theme handler.
   *
   * @var \Drupal\Core\Extension\ThemeHandlerInterface
   */
  protected $themeHandler;

  /**
   * {@inheritdoc}
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, RouteProviderInterface $route_provider, ThemeHandlerInterface $theme_handler) {
    $this->entityTypeManager = $entity_type_manager;
    $this->moduleHandler = $module_handler;
    $this->routeProvider = $route_provider;
    $this->themeHandler = $theme_handler;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $links = [];

    // If module event enabled.
    if ($this->moduleHandler
      ->moduleExists('admin_toolbar')) {
      $links['event.type_add'] = [
        'title' => $this
          ->t('Add event type'),
        'route_name' => 'entity.event_type.add_form',
        'parent' => 'entity.event_type.collection',
        'weight' => -2,
      ] + $base_plugin_definition;

      // Displays event link in toolbar.
      $links['event_page'] = [
        'title' => $this
          ->t('Events'),
        'route_name' => 'entity.event.collection',
        'parent' => 'system.admin_content',
      ] + $base_plugin_definition;
      $links['add_event'] = [
        'title' => $this
          ->t('Add event'),
        'route_name' => 'entity.event.add_page',
        'parent' => $base_plugin_definition['id'] . ':event_page',
      ] + $base_plugin_definition;

      // Adds links for each event type.
      foreach ($this->entityTypeManager
        ->getStorage('event_type')
        ->loadMultiple() as $type) {
        $links['event.add.' . $type
          ->id()] = [
          'title' => $type
            ->label(),
          'route_name' => 'entity.event.add_form',
          'parent' => $base_plugin_definition['id'] . ':add_event',
          'route_parameters' => [
            'event_type' => $type
              ->id(),
          ],
        ] + $base_plugin_definition;
      }
    }
    return $links;
  }

}

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
MenuLinks::$entityTypeManager protected property The entity type manager.
MenuLinks::$moduleHandler protected property The module handler.
MenuLinks::$routeProvider protected property The route provider.
MenuLinks::$themeHandler protected property The theme handler.
MenuLinks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
MenuLinks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
MenuLinks::MAX_BUNDLE_NUMBER constant
MenuLinks::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.