class DeprecatedUserRoutesSubscriber

Same name and namespace in other branches
  1. 11.x core/modules/rest/src/EventSubscriber/DeprecatedUserRoutesSubscriber.php \Drupal\rest\EventSubscriber\DeprecatedUserRoutesSubscriber

Replace the deprecated user module routes with our own.

Hierarchy

Expanded class hierarchy of DeprecatedUserRoutesSubscriber

File

core/modules/rest/src/EventSubscriber/DeprecatedUserRoutesSubscriber.php, line 12

Namespace

Drupal\rest\EventSubscriber
View source
class DeprecatedUserRoutesSubscriber implements EventSubscriberInterface {
  
  /**
   * Replace the deprecated controllers on user.module's routes with ours.
   *
   * @param \Drupal\Core\Routing\RouteBuildEvent $event
   *   The route build event.
   */
  public function onRouteAlter(RouteBuildEvent $event) : void {
    foreach ([
      'pass',
      'login',
      'login_status',
      'logout',
    ] as $route_name) {
      $user_route = $event->getRouteCollection()
        ->get("user.{$route_name}.http");
      $rest_route = $event->getRouteCollection()
        ->get("rest.{$route_name}");
      if ($user_route && $rest_route) {
        $user_route->setDefault('_controller', $rest_route->getDefault('_controller'));
      }
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() : array {
    $events[RoutingEvents::ALTER] = 'onRouteAlter';
    return $events;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.