/** * Checks that the Configuration module is not being uninstalled. * * @param ConfigImporterEvent $event * The config import event. */ public function onConfigImporterValidate(ConfigImporterEvent $event) { $importer = $event->getConfigImporter(); $core_extension = $importer->getStorageComparer()->getSourceStorage()->read('core.extension'); if (!isset($core_extension['module']['config'])) { $importer->logError($this->t('Can not uninstall the Configuration module as part of a configuration synchronization through the user interface.')); } }
/** * Validates the configuration to be imported. * * @param \Drupal\Core\Config\ConfigImporterEvent $event * The Event to process. * * @throws \Drupal\Core\Config\ConfigNameException */ public function onConfigImporterValidate(ConfigImporterEvent $event) { if ($this->state->get('config_import_test.config_import_validate_fail', FALSE)) { // Log more than one error to test multiple validation errors. $event->getConfigImporter()->logError('Config import validate error 1.'); $event->getConfigImporter()->logError('Config import validate error 2.'); } }
/** * Checks that the configuration synchronization is valid. * * This event listener implements two checks: * - prevents deleting all configuration. * - checks that the system.site:uuid's in the source and target match. * * @param ConfigImporterEvent $event * The config import event. */ public function onConfigImporterValidate(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.')); } if (!$event->getConfigImporter()->getStorageComparer()->validateSiteUuid()) { $event->getConfigImporter()->logError($this->t('Site UUID in source storage does not match the target storage.')); } }
/** * Validates the configuration to be imported. * * @param \Drupal\Core\Config\ConfigImporterEvent $event * The Event to process. * * @throws \Drupal\Core\Config\ConfigNameException */ public function onConfigImporterValidate(ConfigImporterEvent $event) { foreach (array('delete', 'create', 'update') as $op) { foreach ($event->getConfigImporter()->getUnprocessedConfiguration($op) as $name) { try { Config::validateName($name); } catch (ConfigNameException $e) { $message = $this->t('The config name @config_name is invalid.', array('@config_name' => $name)); $event->getConfigImporter()->logError($message); } } } }
/** * Validates the configuration to be imported. * * @param \Drupal\Core\Config\ConfigImporterEvent $event * The Event to process. * * @throws \Drupal\Core\Config\ConfigNameException */ public function onConfigImporterValidate(ConfigImporterEvent $event) { foreach (array('delete', 'create', 'update') as $op) { foreach ($event->getConfigImporter()->getUnprocessedConfiguration($op) as $name) { try { Config::validateName($name); } catch (ConfigNameException $e) { $message = $this->t('The config name @config_name is invalid.', array('@config_name' => $name)); $event->getConfigImporter()->logError($message); } } } $config_importer = $event->getConfigImporter(); if ($config_importer->getStorageComparer()->getSourceStorage()->exists('core.extension')) { $this->validateModules($config_importer); $this->validateThemes($config_importer); $this->validateDependencies($config_importer); } else { $config_importer->logError($this->t('The core.extension configuration does not exist.')); } }
/** * Ensures bundles that will be deleted are not in use. * * @param \Drupal\Core\Config\ConfigImporterEvent $event * The config import event. */ public function onConfigImporterValidate(ConfigImporterEvent $event) { foreach ($event->getChangelist('delete') as $config_name) { // Get the config entity type ID. This also ensure we are dealing with a // configuration entity. if ($entity_type_id = $this->configManager->getEntityTypeIdByName($config_name)) { $entity_type = $this->entityManager->getDefinition($entity_type_id); // Does this entity type define a bundle of another entity type. if ($bundle_of = $entity_type->getBundleOf()) { // Work out if there are entities with this bundle. $bundle_of_entity_type = $this->entityManager->getDefinition($bundle_of); $bundle_id = ConfigEntityStorage::getIDFromConfigName($config_name, $entity_type->getConfigPrefix()); $entity_query = $this->entityManager->getStorage($bundle_of)->getQuery(); $entity_ids = $entity_query->condition($bundle_of_entity_type->getKey('bundle'), $bundle_id)->accessCheck(FALSE)->range(0, 1)->execute(); if (!empty($entity_ids)) { $entity = $this->entityManager->getStorage($entity_type_id)->load($bundle_id); $event->getConfigImporter()->logError($this->t('Entities exist of type %entity_type and %bundle_label %bundle. These entities need to be deleted before importing.', array('%entity_type' => $bundle_of_entity_type->getLabel(), '%bundle_label' => $bundle_of_entity_type->getBundleLabel(), '%bundle' => $entity->label()))); } } } } }
/** * Checks that the configuration synchronization is valid. * * This event listener checks that the system.site:uuid's in the source and * target match. * * @param ConfigImporterEvent $event * The config import event. */ public function onConfigImporterValidateSiteUUID(ConfigImporterEvent $event) { if (!$event->getConfigImporter()->getStorageComparer()->validateSiteUuid()) { $event->getConfigImporter()->logError($this->t('Site UUID in source storage does not match the target storage.')); } }