Chris@0: routerBuilder = $router_builder; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Rebuilds the router when the default or admin theme is changed. Chris@0: * Chris@0: * @param \Drupal\Core\Config\ConfigCrudEvent $event Chris@0: */ Chris@0: public function onConfigSave(ConfigCrudEvent $event) { Chris@0: $saved_config = $event->getConfig(); Chris@0: if ($saved_config->getName() == 'system.theme' && ($event->isChanged('admin') || $event->isChanged('default'))) { Chris@0: $this->routerBuilder->setRebuildNeeded(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks that the configuration synchronization is valid. Chris@0: * Chris@0: * This event listener prevents deleting all configuration. If there is Chris@0: * nothing to import then event propagation is stopped because there is no Chris@0: * config import to validate. Chris@0: * Chris@0: * @param \Drupal\Core\Config\ConfigImporterEvent $event Chris@0: * The config import event. Chris@0: */ Chris@0: public function onConfigImporterValidateNotEmpty(ConfigImporterEvent $event) { Chris@0: $importList = $event->getConfigImporter()->getStorageComparer()->getSourceStorage()->listAll(); Chris@0: if (empty($importList)) { Chris@0: $event->getConfigImporter()->logError($this->t('This import is empty and if applied would delete all of your configuration, so has been rejected.')); Chris@0: $event->stopPropagation(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks that the configuration synchronization is valid. Chris@0: * Chris@0: * This event listener checks that the system.site:uuid's in the source and Chris@0: * target match. Chris@0: * Chris@12: * @param \Drupal\Core\Config\ConfigImporterEvent $event Chris@0: * The config import event. Chris@0: */ Chris@0: public function onConfigImporterValidateSiteUUID(ConfigImporterEvent $event) { Chris@17: if (!$event->getConfigImporter()->getStorageComparer()->getSourceStorage()->exists('system.site')) { Chris@17: $event->getConfigImporter()->logError($this->t('This import does not contain system.site configuration, so has been rejected.')); Chris@17: } Chris@0: if (!$event->getConfigImporter()->getStorageComparer()->validateSiteUuid()) { Chris@0: $event->getConfigImporter()->logError($this->t('Site UUID in source storage does not match the target storage.')); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getSubscribedEvents() { Chris@0: $events[ConfigEvents::SAVE][] = ['onConfigSave', 0]; Chris@0: // The empty check has a high priority so that it can stop propagation if Chris@0: // there is no configuration to import. Chris@0: $events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidateNotEmpty', 512]; Chris@0: $events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidateSiteUUID', 256]; Chris@0: return $events; Chris@0: } Chris@0: Chris@0: }