You are here

public function ConfigImporter::validate in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Config/ConfigImporter.php \Drupal\Core\Config\ConfigImporter::validate()
  2. 10 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 730

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.', [
          '@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.', [
          '@old_name' => $names['old_name'],
          '@new_name' => $names['new_name'],
        ]));
      }
    }
    $this->eventDispatcher
      ->dispatch(new ConfigImporterEvent($this), ConfigEvents::IMPORT_VALIDATE);
    if (count($this
      ->getErrors())) {
      $errors = array_merge([
        'There were errors validating the config synchronization.',
      ], $this
        ->getErrors());
      throw new ConfigImporterException(implode(PHP_EOL, $errors));
    }
    else {
      $this->validated = TRUE;
    }
  }
  return $this;
}