ConfigInstaller::installDefaultConfig

public ConfigInstaller::installDefaultConfig($type, $name)

Installs the default configuration of a given extension.

When an extension is installed, it searches all the default configuration directories for all other extensions to locate any configuration with its name prefix. For example, the Node module provides the frontpage view as a default configuration file: core/modules/node/config/install/views.view.frontpage.yml When the Views module is installed after the Node module is already enabled, the frontpage view will be installed.

Additionally, the default configuration directory for the extension being installed is searched to discover if it contains default configuration that is owned by other enabled extensions. So, the frontpage view will also be installed when the Node module is installed after Views.

Parameters

string $type: The extension type; e.g., 'module' or 'theme'.

string $name: The name of the module or theme to install default configuration for.

Overrides ConfigInstallerInterface::installDefaultConfig

See also

\Drupal\Core\Config\ExtensionInstallStorage

File

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

Class

ConfigInstaller

Namespace

Drupal\Core\Config

Code

public function installDefaultConfig($type, $name) {
  $extension_path = $this->drupalGetPath($type, $name);
  // Refresh the schema cache if the extension provides configuration schema
  // or is a theme.
  if (is_dir($extension_path . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY) || $type == 'theme') {
    $this->typedConfig->clearCachedDefinitions();
  }

  $default_install_path = $this->getDefaultConfigDirectory($type, $name);
  if (is_dir($default_install_path)) {
    if (!$this->isSyncing()) {
      $storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);
      $prefix = '';
    }
    else {
      // The configuration importer sets the source storage on the config
      // installer. The configuration importer handles all of the
      // configuration entity imports. We only need to ensure that simple
      // configuration is created when the extension is installed.
      $storage = $this->getSourceStorage();
      $prefix = $name . '.';
    }

    // Gets profile storages to search for overrides if necessary.
    $profile_storages = $this->getProfileStorages($name);

    // Gather information about all the supported collections.
    $collection_info = $this->configManager->getConfigCollectionInfo();
    foreach ($collection_info->getCollectionNames() as $collection) {
      $config_to_create = $this->getConfigToCreate($storage, $collection, $prefix, $profile_storages);
      // If we're installing a profile ensure configuration that is overriding
      // is excluded.
      if ($name == $this->drupalGetProfile()) {
        $existing_configuration = $this->getActiveStorages($collection)->listAll();
        $config_to_create = array_diff_key($config_to_create, array_flip($existing_configuration));
      }
      if (!empty($config_to_create)) {
        $this->createConfiguration($collection, $config_to_create);
      }
    }
  }

  // During a drupal installation optional configuration is installed at the
  // end of the installation process.
  // @see install_install_profile()
  if (!$this->isSyncing() && !$this->drupalInstallationAttempted()) {
    $optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
    if (is_dir($optional_install_path)) {
      // Install any optional config the module provides.
      $storage = new FileStorage($optional_install_path, StorageInterface::DEFAULT_COLLECTION);
      $this->installOptionalConfig($storage, '');
    }
    // Install any optional configuration entities whose dependencies can now
    // be met. This searches all the installed modules config/optional
    // directories.
    $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE);
    $this->installOptionalConfig($storage, [$type => $name]);
  }

  // Reset all the static caches and list caches.
  $this->configFactory->reset();
}
doc_Drupal
2016-10-29 08:53:54
Comments
Leave a Comment

Please login to continue.