You are here

RouteSubscriber.php in Menu Link Clone 8

File

src/Routing/RouteSubscriber.php
View source
<?php

namespace Drupal\menu_link_clone\Routing;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Listens to the dynamic route events.
 */
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) {
      if ($entity_type_id == 'menu') {
        if ($route = $collection
          ->get("entity.{$entity_type_id}.clone_form")) {
          $route
            ->setDefault('_form', '\\Drupal\\menu_link_clone\\Form\\EntityMenuLinkCloneForm');
        }
      }
    }
  }

}

Classes

Namesort descending Description
RouteSubscriber Listens to the dynamic route events.