You are here

class RouteSubscriber in Empty Front Page 8

Subscriber for Empty Front page routes.

Hierarchy

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

Expanded class hierarchy of RouteSubscriber

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

File

src/Routing/RouteSubscriber.php, line 17
Contains \Drupal\empty_front_page\Routing\RouteSubscriber.

Namespace

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

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    $front_page = \Drupal::config('system.site')
      ->get('page.front');
    foreach ($collection as $route) {
      if ($route
        ->getPath() == '/' . $front_page) {
        $route
          ->setDefaults([
          '_content' => [
            $this,
            'content',
          ],
        ]);
        break;
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = parent::getSubscribedEvents();

    // Ensure to run after the views route subscriber.
    // @see \Drupal\views\EventSubscriber
    $events[RoutingEvents::ALTER] = [
      'onAlterRoutes',
      -180,
    ];
    return $events;
  }

  /**
   * Content callback.
   */
  public static function content() {
    return [
      '#markup' => '',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::content public static function Content callback.
RouteSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase::getSubscribedEvents
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1