Skip to content
Snippets Groups Projects
Unverified Commit d746ffc0 authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch Committed by Mateu Aguiló Bosch
Browse files

Issue #2982133 by e0ipso: Do not rebuild container during CLI install

parent 08698148
No related branches found
No related tags found
No related merge requests found
......@@ -50,16 +50,19 @@ class ConfigSubscriber implements EventSubscriberInterface {
* The Event to process.
*/
public function onSave(ConfigCrudEvent $event) {
if ($event->getConfig()->getName() === 'jsonapi_extras.settings') {
$container = \Drupal::getContainer();
// It is problematic to rebuild the container during the installation.
$should_process = $container->getParameter('kernel.environment') !== 'install'
&& $event->getConfig()->getName() === 'jsonapi_extras.settings';
if ($should_process) {
// @see \Drupal\jsonapi_extras\JsonapiExtrasServiceProvider::alter()
if ($event->isChanged('path_prefix')) {
$this->drupalKernel->rebuildContainer();
$container = \Drupal::getContainer();
// Because \Drupal\jsonapi\Routing\Routes::routes() uses a container
// parameter, we need to ensure that it uses the freshly rebuilt
// container. Due to that, it's impossible to use an injected route
// builder service, at least until core updates it to support
// \Drupal\Core\DrupalKernelInterface::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED
// \Drupal\Core\DrupalKernelInterface::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED.
$this->service = $container->get('router.builder');
$container->get('router.builder')->rebuild();
}
......@@ -68,7 +71,9 @@ class ConfigSubscriber implements EventSubscriberInterface {
/**
* Associates JSON API Extras' config cache tag with all JSON API responses.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The response event.
*/
public function onResponse(FilterResponseEvent $event) {
if ($event->getRequest()->getRequestFormat() !== 'api_json') {
......@@ -87,12 +92,13 @@ class ConfigSubscriber implements EventSubscriberInterface {
]);
}
/**
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ConfigEvents::SAVE][] = ['onSave'];
// Run before \Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber::onResponse()
// Run before
// \Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber::onResponse()
// (priority 128), so we can add JSON API's config cache tag.
$events[KernelEvents::RESPONSE][] = ['onResponse', 150];
return $events;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment