You are here

public function MenuLinks::getDerivativeDefinitions in Event 8

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

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

Class

MenuLinks
Provides a default implementation for menu link plugins.

Namespace

Drupal\event\Plugin\Derivative

Code

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;
}