comparison core/modules/big_pipe/src/EventSubscriber/NoBigPipeRouteAlterSubscriber.php @ 0:c75dbcec494b

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