You are here

class RouteSubscriber in Convert Bundles 8

Subscriber for convert_bundles routes.

Hierarchy

  • class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RouteSubscriber

See also

\Drupal\convert_bundles\Plugin\Derivative\ConvertBundlesLocalTask

1 string reference to 'RouteSubscriber'
convert_bundles.services.yml in ./convert_bundles.services.yml
convert_bundles.services.yml
1 service uses RouteSubscriber
convert_bundles.route_subscriber in ./convert_bundles.services.yml
Drupal\convert_bundles\Routing\RouteSubscriber

File

src/Routing/RouteSubscriber.php, line 16

Namespace

Drupal\convert_bundles\Routing
View source
class RouteSubscriber extends RouteSubscriberBase {

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

  /**
   * Constructs a new RouteSubscriber object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager) {
    $this->entityTypeManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {
      $route = new Route("/{$entity_type_id}/{{$entity_type_id}}/convertbundles");
      $route
        ->addDefaults([
        '_controller' => '\\Drupal\\convert_bundles\\Controller\\EntityController::getEntity',
        '_title' => 'Convert Bundle',
      ])
        ->addRequirements([
        '_permission' => 'administer convert_bundles',
      ])
        ->setOption('_admin_route', TRUE)
        ->setOption('_convert_bundles_entity_type_id', $entity_type_id)
        ->setOption('parameters', [
        $entity_type_id => [
          'type' => 'entity:' . $entity_type_id,
        ],
      ]);
      $collection
        ->add("entity.{$entity_type_id}.convert_bundles", $route);
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = parent::getSubscribedEvents();
    $events[RoutingEvents::ALTER] = [
      'onAlterRoutes',
      100,
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::$entityTypeManager protected property The entity type manager service.
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase::getSubscribedEvents
RouteSubscriber::__construct public function Constructs a new RouteSubscriber object.
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1