You are here

function drupal_install_config_directories in Drupal 8

Creates the config directory and ensures it is operational.

Deprecated

in drupal:8.8.0 and is removed from drupal:9.0.0. There is no replacement.

See also

https://www.drupal.org/node/3018145

File

core/includes/install.inc, line 534
API functions for installing modules and themes.

Code

function drupal_install_config_directories() {
  @trigger_error('drupal_install_config_directories() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. There is no replacement. See https://www.drupal.org/node/3018145.', E_USER_DEPRECATED);
  global $config_directories, $install_state;

  // If settings.php does not contain a config sync directory name we need to
  // configure one.
  if (empty($config_directories[CONFIG_SYNC_DIRECTORY])) {
    if (empty($install_state['config_install_path'])) {

      // Add a randomized config directory name to settings.php
      $config_directories[CONFIG_SYNC_DIRECTORY] = \Drupal::service('site.path') . '/files/config_' . Crypt::randomBytesBase64(55) . '/sync';
    }
    else {

      // Install profiles can contain a config sync directory. If they do,
      // 'config_install_path' is a path to the directory.
      $config_directories[CONFIG_SYNC_DIRECTORY] = $install_state['config_install_path'];
    }
    $settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) [
      'value' => $config_directories[CONFIG_SYNC_DIRECTORY],
      'required' => TRUE,
    ];

    // Rewrite settings.php, which also sets the value as global variable.
    drupal_rewrite_settings($settings);
  }

  // This should never fail, since if the config directory was specified in
  // settings.php it will have already been created and verified earlier, and
  // if it wasn't specified in settings.php, it is created here inside the
  // public files directory, which has already been verified to be writable
  // itself. But if it somehow fails anyway, the installation cannot proceed.
  // Bail out using a similar error message as in system_requirements().
  if (!\Drupal::service('file_system')
    ->prepareDirectory($config_directories[CONFIG_SYNC_DIRECTORY], FileSystemInterface::CREATE_DIRECTORY) && !file_exists($config_directories[CONFIG_SYNC_DIRECTORY])) {
    throw new Exception("The directory '" . config_get_config_directory(CONFIG_SYNC_DIRECTORY) . "' could not be created. To proceed with the installation, either create the directory or ensure that the installer has the permissions to create it automatically. For more information, see the <a href='https://www.drupal.org/server-permissions'>online handbook</a>.");
  }
  elseif (is_writable($config_directories[CONFIG_SYNC_DIRECTORY])) {

    // Put a README.txt into the sync config directory. This is required so that
    // they can later be added to git. Since this directory is auto-created, we
    // have to write out the README rather than just adding it to the drupal core
    // repo.
    $text = 'This directory contains configuration to be imported into your Drupal site. To make this configuration active, visit admin/config/development/configuration/sync.' . ' For information about deploying configuration between servers, see https://www.drupal.org/documentation/administer/config';
    file_put_contents(config_get_config_directory(CONFIG_SYNC_DIRECTORY) . '/README.txt', "{$text}\n");
  }
}