Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\big_pipe\EventSubscriber;
|
Chris@0
|
4
|
Chris@0
|
5 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
Chris@0
|
6 use Drupal\Core\Routing\RoutingEvents;
|
Chris@0
|
7 use Drupal\Core\Routing\RouteBuildEvent;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Sets the '_no_big_pipe' option on select routes.
|
Chris@0
|
11 */
|
Chris@0
|
12 class NoBigPipeRouteAlterSubscriber implements EventSubscriberInterface {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Alters select routes to have the '_no_big_pipe' option.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @param \Drupal\Core\Routing\RouteBuildEvent $event
|
Chris@0
|
18 * The event to process.
|
Chris@0
|
19 */
|
Chris@0
|
20 public function onRoutingRouteAlterSetNoBigPipe(RouteBuildEvent $event) {
|
Chris@0
|
21 $no_big_pipe_routes = [
|
Chris@0
|
22 // The batch system uses a <meta> refresh to work without JavaScript.
|
Chris@0
|
23 'system.batch_page.html',
|
Chris@0
|
24 // When a user would install the BigPipe module using a browser and with
|
Chris@0
|
25 // JavaScript disabled, the first response contains the status messages
|
Chris@0
|
26 // for installing a module, but then the BigPipe no-JS redirect occurs,
|
Chris@0
|
27 // which then causes the user to not see those status messages.
|
Chris@0
|
28 // @see https://www.drupal.org/node/2469431#comment-10901944
|
Chris@0
|
29 'system.modules_list',
|
Chris@0
|
30 ];
|
Chris@0
|
31
|
Chris@0
|
32 $route_collection = $event->getRouteCollection();
|
Chris@0
|
33 foreach ($no_big_pipe_routes as $excluded_route) {
|
Chris@0
|
34 if ($route = $route_collection->get($excluded_route)) {
|
Chris@0
|
35 $route->setOption('_no_big_pipe', TRUE);
|
Chris@0
|
36 }
|
Chris@0
|
37 }
|
Chris@0
|
38 }
|
Chris@0
|
39
|
Chris@0
|
40 /**
|
Chris@0
|
41 * {@inheritdoc}
|
Chris@0
|
42 */
|
Chris@0
|
43 public static function getSubscribedEvents() {
|
Chris@0
|
44 $events[RoutingEvents::ALTER][] = ['onRoutingRouteAlterSetNoBigPipe'];
|
Chris@0
|
45 return $events;
|
Chris@0
|
46 }
|
Chris@0
|
47
|
Chris@0
|
48 }
|