You are here

class RouteSubscriber in Menu Link Clone 8

Same name and namespace in other branches
  1. 8.3 src/Routing/RouteSubscriber.php \Drupal\menu_link_clone\Routing\RouteSubscriber
  2. 8.2 src/Routing/RouteSubscriber.php \Drupal\menu_link_clone\Routing\RouteSubscriber

Listens to the dynamic route events.

Hierarchy

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

Expanded class hierarchy of RouteSubscriber

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

File

src/Routing/RouteSubscriber.php, line 12

Namespace

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

}

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::__construct public function Constructs a new RouteSubscriber object.
RouteSubscriberBase::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. 5
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1