Same filename and directory in other branches
- 8.9.x core/modules/system/src/SystemConfigSubscriber.php
- 9 core/modules/system/src/SystemConfigSubscriber.php
Namespace
Drupal\system
File
core/modules/system/src/SystemConfigSubscriber.php
View source
<?php
namespace Drupal\system;
use Drupal\Core\Config\ConfigCrudEvent;
use Drupal\Core\Config\ConfigEvents;
use Drupal\Core\Config\ConfigImporterEvent;
use Drupal\Core\Routing\RouteBuilderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class SystemConfigSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
protected $routerBuilder;
public function __construct(RouteBuilderInterface $router_builder) {
$this->routerBuilder = $router_builder;
}
public function onConfigSave(ConfigCrudEvent $event) {
$saved_config = $event
->getConfig();
if ($saved_config
->getName() == 'system.theme' && ($event
->isChanged('admin') || $event
->isChanged('default'))) {
$this->routerBuilder
->setRebuildNeeded();
}
}
public function onConfigImporterValidateNotEmpty(ConfigImporterEvent $event) {
$importList = $event
->getConfigImporter()
->getStorageComparer()
->getSourceStorage()
->listAll();
if (empty($importList)) {
$event
->getConfigImporter()
->logError($this
->t('This import is empty and if applied would delete all of your configuration, so has been rejected.'));
$event
->stopPropagation();
}
}
public function onConfigImporterValidateSiteUUID(ConfigImporterEvent $event) {
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.'));
}
if (!$event
->getConfigImporter()
->getStorageComparer()
->validateSiteUuid()) {
$event
->getConfigImporter()
->logError($this
->t('Site UUID in source storage does not match the target storage.'));
}
}
public static function getSubscribedEvents() : array {
$events[ConfigEvents::SAVE][] = [
'onConfigSave',
0,
];
$events[ConfigEvents::IMPORT_VALIDATE][] = [
'onConfigImporterValidateNotEmpty',
512,
];
$events[ConfigEvents::IMPORT_VALIDATE][] = [
'onConfigImporterValidateSiteUUID',
256,
];
return $events;
}
}
Classes