W3cubDocs

/Drupal 8

public function ConfigImporter::validate

public ConfigImporter::validate()

Dispatches validate event for a ConfigImporter object.

Events should throw a \Drupal\Core\Config\ConfigImporterException to prevent an import from occurring.

Throws

\Drupal\Core\Config\ConfigImporterException Exception thrown if the validate event logged any errors.

File

core/lib/Drupal/Core/Config/ConfigImporter.php, line 709

Class

ConfigImporter
Defines a configuration importer.

Namespace

Drupal\Core\Config

Code

public function validate() {
  if (!$this->validated) {
    // Create the list of installs and uninstalls.
    $this->createExtensionChangelist();
    // Validate renames.
    foreach ($this->getUnprocessedConfiguration('rename') as $name) {
      $names = $this->storageComparer->extractRenameNames($name);
      $old_entity_type_id = $this->configManager->getEntityTypeIdByName($names['old_name']);
      $new_entity_type_id = $this->configManager->getEntityTypeIdByName($names['new_name']);
      if ($old_entity_type_id != $new_entity_type_id) {
        $this->logError($this->t('Entity type mismatch on rename. @old_type not equal to @new_type for existing configuration @old_name and staged configuration @new_name.', array('@old_type' => $old_entity_type_id, '@new_type' => $new_entity_type_id, '@old_name' => $names['old_name'], '@new_name' => $names['new_name'])));
      }
      // Has to be a configuration entity.
      if (!$old_entity_type_id) {
        $this->logError($this->t('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', array('@old_name' => $names['old_name'], '@new_name' => $names['new_name'])));
      }
    }
    $this->eventDispatcher->dispatch(ConfigEvents::IMPORT_VALIDATE, new ConfigImporterEvent($this));
    if (count($this->getErrors())) {
      throw new ConfigImporterException('There were errors validating the config synchronization.');
    }
    else {
      $this->validated = TRUE;
    }
  }
  return $this;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!ConfigImporter.php/function/ConfigImporter::validate/8.1.x