Commit f3f974cf authored by catch's avatar catch
Browse files

Issue #2980237 by Upchuk, alexpott: Rebuilding routes when...

Issue #2980237 by Upchuk, alexpott: Rebuilding routes when node.settings:use_admin_theme changes should be done in a config listener
parent da44172f
......@@ -880,7 +880,6 @@ function node_form_system_themes_admin_form_submit($form, FormStateInterface $fo
\Drupal::configFactory()->getEditable('node.settings')
->set('use_admin_theme', $form_state->getValue('use_admin_theme'))
->save();
\Drupal::service('router.builder')->setRebuildNeeded();
}
/**
......
......@@ -25,7 +25,7 @@ services:
- { name: access_check, applies_to: _node_preview_access }
node.admin_path.route_subscriber:
class: Drupal\node\EventSubscriber\NodeAdminRouteSubscriber
arguments: ['@config.factory']
arguments: ['@config.factory', '@router.builder']
tags:
- { name: event_subscriber }
node_preview:
......
......@@ -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;
......@@ -18,14 +21,24 @@ class NodeAdminRouteSubscriber extends RouteSubscriberBase {
*/
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 @@ protected function alterRoutes(RouteCollection $collection) {
}
}
/**
* 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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment