2013-06-08 20:10:53 +00:00
|
|
|
<?php
|
2014-01-29 11:07:59 +00:00
|
|
|
|
2013-06-08 20:10:53 +00:00
|
|
|
namespace Drupal\system;
|
|
|
|
|
2015-11-06 23:09:03 +00:00
|
|
|
use Drupal\Core\Config\ConfigCrudEvent;
|
2015-05-17 20:18:22 +00:00
|
|
|
use Drupal\Core\Config\ConfigEvents;
|
2013-06-08 20:10:53 +00:00
|
|
|
use Drupal\Core\Config\ConfigImporterEvent;
|
2015-11-06 23:09:03 +00:00
|
|
|
use Drupal\Core\Routing\RouteBuilderInterface;
|
2015-05-17 20:18:22 +00:00
|
|
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
2013-06-08 20:10:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* System Config subscriber.
|
|
|
|
*/
|
2015-05-17 20:18:22 +00:00
|
|
|
class SystemConfigSubscriber implements EventSubscriberInterface {
|
|
|
|
use StringTranslationTrait;
|
2013-06-08 20:10:53 +00:00
|
|
|
|
2015-11-06 23:09:03 +00:00
|
|
|
/**
|
|
|
|
* The router builder.
|
|
|
|
*
|
|
|
|
* @var \Drupal\Core\Routing\RouteBuilderInterface
|
|
|
|
*/
|
|
|
|
protected $routerBuilder;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs the SystemConfigSubscriber.
|
|
|
|
*
|
2017-09-04 17:30:59 +00:00
|
|
|
* @param \Drupal\Core\Routing\RouteBuilderInterface $router_builder
|
2015-11-06 23:09:03 +00:00
|
|
|
* The router builder service.
|
|
|
|
*/
|
|
|
|
public function __construct(RouteBuilderInterface $router_builder) {
|
|
|
|
$this->routerBuilder = $router_builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rebuilds the router when the default or admin theme is changed.
|
|
|
|
*
|
|
|
|
* @param \Drupal\Core\Config\ConfigCrudEvent $event
|
|
|
|
*/
|
|
|
|
public function onConfigSave(ConfigCrudEvent $event) {
|
|
|
|
$saved_config = $event->getConfig();
|
|
|
|
if ($saved_config->getName() == 'system.theme' && ($event->isChanged('admin') || $event->isChanged('default'))) {
|
|
|
|
$this->routerBuilder->setRebuildNeeded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-08 20:10:53 +00:00
|
|
|
/**
|
2014-04-14 20:44:46 +00:00
|
|
|
* Checks that the configuration synchronization is valid.
|
|
|
|
*
|
2015-05-17 20:18:22 +00:00
|
|
|
* This event listener prevents deleting all configuration. If there is
|
|
|
|
* nothing to import then event propagation is stopped because there is no
|
|
|
|
* config import to validate.
|
2014-01-29 11:07:59 +00:00
|
|
|
*
|
2015-05-17 20:18:22 +00:00
|
|
|
* @param \Drupal\Core\Config\ConfigImporterEvent $event
|
2014-01-29 11:07:59 +00:00
|
|
|
* The config import event.
|
|
|
|
*/
|
2015-05-17 20:18:22 +00:00
|
|
|
public function onConfigImporterValidateNotEmpty(ConfigImporterEvent $event) {
|
2014-01-29 11:07:59 +00:00
|
|
|
$importList = $event->getConfigImporter()->getStorageComparer()->getSourceStorage()->listAll();
|
|
|
|
if (empty($importList)) {
|
2014-04-14 20:44:46 +00:00
|
|
|
$event->getConfigImporter()->logError($this->t('This import is empty and if applied would delete all of your configuration, so has been rejected.'));
|
2015-05-17 20:18:22 +00:00
|
|
|
$event->stopPropagation();
|
2014-04-14 20:44:46 +00:00
|
|
|
}
|
2015-05-17 20:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks that the configuration synchronization is valid.
|
|
|
|
*
|
|
|
|
* This event listener checks that the system.site:uuid's in the source and
|
|
|
|
* target match.
|
|
|
|
*
|
2017-11-16 15:00:40 +00:00
|
|
|
* @param \Drupal\Core\Config\ConfigImporterEvent $event
|
2015-05-17 20:18:22 +00:00
|
|
|
* The config import event.
|
|
|
|
*/
|
|
|
|
public function onConfigImporterValidateSiteUUID(ConfigImporterEvent $event) {
|
Issue #2788777 by alexpott, bircher, jribeiro, Eli-T, mpotter, douggreen, GoZ, DamienMcKenna, Dane Powell, jibran, szeidler, Alumei, andypost, dawehner, johndevman: Allow a site-specific profile to be installed from existing config
2018-06-20 18:03:54 +00:00
|
|
|
if (!$event->getConfigImporter()->getStorageComparer()->getSourceStorage()->exists('system.site')) {
|
|
|
|
$event->getConfigImporter()->logError($this->t('This import does not contain system.site configuration, so has been rejected.'));
|
|
|
|
}
|
2014-04-14 20:44:46 +00:00
|
|
|
if (!$event->getConfigImporter()->getStorageComparer()->validateSiteUuid()) {
|
|
|
|
$event->getConfigImporter()->logError($this->t('Site UUID in source storage does not match the target storage.'));
|
2013-06-08 20:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-17 20:18:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public static function getSubscribedEvents() {
|
2017-03-04 01:20:24 +00:00
|
|
|
$events[ConfigEvents::SAVE][] = ['onConfigSave', 0];
|
2016-01-25 15:46:37 +00:00
|
|
|
// The empty check has a high priority so that it can stop propagation if
|
2015-05-17 20:18:22 +00:00
|
|
|
// there is no configuration to import.
|
2017-03-04 01:20:24 +00:00
|
|
|
$events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidateNotEmpty', 512];
|
|
|
|
$events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidateSiteUUID', 256];
|
2015-05-17 20:18:22 +00:00
|
|
|
return $events;
|
|
|
|
}
|
2016-05-08 15:05:38 +00:00
|
|
|
|
2013-06-08 20:10:53 +00:00
|
|
|
}
|