diff core/modules/node/src/EventSubscriber/NodeAdminRouteSubscriber.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 4c8ae668cc8c
children
line wrap: on
line diff
--- a/core/modules/node/src/EventSubscriber/NodeAdminRouteSubscriber.php	Thu Feb 28 13:21:36 2019 +0000
+++ b/core/modules/node/src/EventSubscriber/NodeAdminRouteSubscriber.php	Thu May 09 15:33:08 2019 +0100
@@ -2,7 +2,10 @@
 
 namespace Drupal\node\EventSubscriber;
 
+use Drupal\Core\Config\ConfigCrudEvent;
+use Drupal\Core\Config\ConfigEvents;
 use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\Core\Routing\RouteBuilderInterface;
 use Drupal\Core\Routing\RouteSubscriberBase;
 use Symfony\Component\Routing\RouteCollection;
 
@@ -19,13 +22,23 @@
   protected $configFactory;
 
   /**
+   * The router builder.
+   *
+   * @var \Drupal\Core\Routing\RouteBuilderInterface
+   */
+  protected $routerBuilder;
+
+  /**
    * Constructs a new NodeAdminRouteSubscriber.
    *
    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
    *   The config factory.
+   * @param \Drupal\Core\Routing\RouteBuilderInterface $router_builder
+   *   The router builder service.
    */
-  public function __construct(ConfigFactoryInterface $config_factory) {
+  public function __construct(ConfigFactoryInterface $config_factory, RouteBuilderInterface $router_builder) {
     $this->configFactory = $config_factory;
+    $this->routerBuilder = $router_builder;
   }
 
   /**
@@ -41,4 +54,24 @@
     }
   }
 
+  /**
+   * Rebuilds the router when node.settings:use_admin_theme is changed.
+   *
+   * @param \Drupal\Core\Config\ConfigCrudEvent $event
+   */
+  public function onConfigSave(ConfigCrudEvent $event) {
+    if ($event->getConfig()->getName() === 'node.settings' && $event->isChanged('use_admin_theme')) {
+      $this->routerBuilder->setRebuildNeeded();
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    $events = parent::getSubscribedEvents();
+    $events[ConfigEvents::SAVE][] = ['onConfigSave', 0];
+    return $events;
+  }
+
 }