function ConfigInstaller::checkConfigurationToInstall

Same name in this branch
  1. 11.x core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php \Drupal\Core\ProxyClass\Config\ConfigInstaller::checkConfigurationToInstall()
Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php \Drupal\Core\ProxyClass\Config\ConfigInstaller::checkConfigurationToInstall()
  2. 9 core/lib/Drupal/Core/Config/ConfigInstaller.php \Drupal\Core\Config\ConfigInstaller::checkConfigurationToInstall()
  3. 8.9.x core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php \Drupal\Core\ProxyClass\Config\ConfigInstaller::checkConfigurationToInstall()
  4. 8.9.x core/lib/Drupal/Core/Config/ConfigInstaller.php \Drupal\Core\Config\ConfigInstaller::checkConfigurationToInstall()
  5. 10 core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php \Drupal\Core\ProxyClass\Config\ConfigInstaller::checkConfigurationToInstall()
  6. 10 core/lib/Drupal/Core/Config/ConfigInstaller.php \Drupal\Core\Config\ConfigInstaller::checkConfigurationToInstall()

Checks the configuration that will be installed for an extension.

Parameters

string $type: Type of extension to install.

string|array $name: Name or names of extensions to install.

Overrides ConfigInstallerInterface::checkConfigurationToInstall

File

core/lib/Drupal/Core/Config/ConfigInstaller.php, line 550

Class

ConfigInstaller
The config installer.

Namespace

Drupal\Core\Config

Code

public function checkConfigurationToInstall($type, $name) {
  if ($this->isSyncing()) {
    // Configuration is assumed to already be checked by the config importer
    // validation events.
    return;
  }
  $names = (array) $name;
  $enabled_extensions = $this->getEnabledExtensions();
  $previous_config_names = [];
  foreach ($names as $name) {
    // Add the extension that will be enabled to the list of enabled
    // extensions.
    $enabled_extensions[] = $name;
    $config_install_path = $this->getDefaultConfigDirectory($type, $name);
    if (!is_dir($config_install_path)) {
      continue;
    }
    $storage = new FileStorage($config_install_path, StorageInterface::DEFAULT_COLLECTION);
    // Gets profile storages to search for overrides if necessary.
    $profile_storages = $this->getProfileStorages($name);
    // Check the dependencies of configuration provided by the module.
    [
      $invalid_default_config,
      $missing_dependencies,
    ] = $this->findDefaultConfigWithUnmetDependencies($storage, $enabled_extensions, $profile_storages, $previous_config_names);
    if (!empty($invalid_default_config)) {
      throw UnmetDependenciesException::create($name, array_unique($missing_dependencies, SORT_REGULAR));
    }
    // Install profiles can not have config clashes. Configuration that
    // has the same name as a module's configuration will be used instead.
    if ($name !== $this->drupalGetProfile()) {
      // Throw an exception if the module being installed contains
      // configuration that already exists. Additionally, can not continue
      // installing more modules because those may depend on the current
      // module being installed.
      $existing_configuration = $this->findPreExistingConfiguration($storage, $previous_config_names);
      if (!empty($existing_configuration)) {
        throw PreExistingConfigException::create($name, $existing_configuration);
      }
    }
    // Store the config names for the checked module in order to add them to
    // the list of active configuration for the next module.
    foreach ($this->configManager
      ->getConfigCollectionInfo()
      ->getCollectionNames() as $collection) {
      $config_to_create = array_keys($this->getConfigToCreate($storage, $collection));
      if (!isset($previous_config_names[$collection])) {
        $previous_config_names[$collection] = $config_to_create;
      }
      else {
        $previous_config_names[$collection] = array_merge($previous_config_names[$collection], $config_to_create);
      }
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.