Same name and namespace in other branches
  1. 5.x includes/install.inc \drupal_rewrite_settings()
  2. 6.x includes/install.inc \drupal_rewrite_settings()
  3. 7.x includes/install.inc \drupal_rewrite_settings()
  4. 8.9.x core/includes/install.inc \drupal_rewrite_settings()
  5. 9 core/includes/install.inc \drupal_rewrite_settings()

Replaces values in settings.php with values in the submitted array.

This function replaces values in place if possible, even for multidimensional arrays. This way the old settings do not linger, overridden and also the doxygen on a value remains where it should be.

Parameters

$settings: An array of settings that need to be updated. Multidimensional arrays are dumped up to a stdClass object. The object can have value, required and comment properties.

$settings['settings']['config_sync_directory'] = (object) array(
  'value' => 'config_hash/sync',
  'required' => TRUE,
);

gets dumped as:

$settings['config_sync_directory'] = 'config_hash/sync';

Deprecated

in drupal:10.1.0 and is removed from drupal:11.0.0. Use SettingsEditor::rewrite() instead. Note $settings_file argument becomes required and the first argument of the method.

See also

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

\Drupal\Core\Site\SettingsEditor::rewrite()

1 call to drupal_rewrite_settings()
LegacySettingsRewriteTest::testDrupalRewriteSettings in core/tests/Drupal/KernelTests/Core/Site/LegacySettingsRewriteTest.php
Tests the drupal_rewrite_settings() function.

File

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

Code

function drupal_rewrite_settings($settings = [], $settings_file = NULL) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use SettingsEditor::rewrite() instead. The order of the arguments has also changed: $settings_file is now required and is the first argument of the method. See https://www.drupal.org/node/3244583', E_USER_DEPRECATED);
  SettingsEditor::rewrite($settings_file ?? \Drupal::getContainer()
    ->getParameter('site.path') . '/settings.php', $settings);
}