You are here

public function ConfigImporter::validate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Config/ConfigImporter.php \Drupal\Core\Config\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.

1 call to ConfigImporter::validate()
ConfigImporter::initialize in core/lib/Drupal/Core/Config/ConfigImporter.php
Initializes the config importer in preparation for processing a batch.

File

core/lib/Drupal/Core/Config/ConfigImporter.php, line 711
Contains \Drupal\Core\Config\ConfigImporter.

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;
}