diff --git a/core/includes/update.inc b/core/includes/update.inc index acdf83e..44d96a4 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -12,6 +12,7 @@ use Drupal\Core\Config\FileStorage; use Drupal\Core\Config\ConfigException; use Drupal\Component\Uuid\Uuid; +use Drupal\Component\Utility\NestedArray; /** * Minimum schema version of Drupal 7 required for upgrade to Drupal 8. @@ -1202,18 +1203,15 @@ function update_variables_to_config($config_name, array $variable_map) { } $default_data = $file->read($config_name); + // Apply the default values. + $config->setData($default_data); + // Merge any possibly existing original data into default values. // Only relevant when being called repetitively on the same config object. if (!empty($original_data)) { - $data = drupal_array_merge_deep($default_data, $original_data); - } - else { - $data = $default_data; + $config->merge($original_data); } - // Apply the default values. - $config->setData($data); - // Fetch existing variables. $variables = db_query('SELECT name, value FROM {variable} WHERE name IN (:variables)', array(':variables' => array_keys($variable_map)))->fetchAllKeyed(); diff --git a/core/lib/Drupal/Component/Utility/NestedArray.php b/core/lib/Drupal/Component/Utility/NestedArray.php index 6617c68..e6ab1ee 100644 --- a/core/lib/Drupal/Component/Utility/NestedArray.php +++ b/core/lib/Drupal/Component/Utility/NestedArray.php @@ -315,19 +315,19 @@ public static function mergeDeep() { * * @see NestedArray::mergeDeep() */ - public static function mergeDeepArray(array $arrays) { + public static function mergeDeepArray(array $arrays, $preserve_integer_keys = FALSE) { $result = array(); foreach ($arrays as $array) { foreach ($array as $key => $value) { - // Renumber integer keys as array_merge_recursive() does. Note that PHP - // automatically converts array keys that are integer strings (e.g., '1') - // to integers. - if (is_integer($key)) { + // Renumber integer keys as array_merge_recursive() does unless + // $preserve_integer_keys is set to TRUE. Note that PHP automatically + // converts array keys that are integer strings (e.g., '1') to integers. + if (is_integer($key) && !$preserve_integer_keys) { $result[] = $value; } // Recurse when both values are arrays. elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) { - $result[$key] = self::mergeDeepArray(array($result[$key], $value)); + $result[$key] = self::mergeDeepArray(array($result[$key], $value), $preserve_integer_keys); } // Otherwise, use the latter value, overriding any previous value. else { diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 3fe9563..c63b2a0 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -401,4 +401,19 @@ public function getStorage() { protected function notify($config_event_name) { $this->eventDispatcher->dispatch('config.' . $config_event_name, new ConfigEvent($this)); } + + /* + * Merges data into a configuration object. + * + * @param array $data_to_merge + * An array containing data to merge. + * + * @return Drupal\Core\Config\Config + * The configuration object. + */ + public function merge(array $data_to_merge) { + // Preserve integer keys so that config keys are not changed. + $this->data = NestedArray::mergeDeepArray(array($this->data, $data_to_merge), TRUE); + return $this; + } } diff --git a/core/modules/system/config/system.site.yml b/core/modules/system/config/system.site.yml index 010dedf..ee9b6a7 100644 --- a/core/modules/system/config/system.site.yml +++ b/core/modules/system/config/system.site.yml @@ -5,3 +5,4 @@ page: 403: '' 404: '' front: user +admin_compact_mode: '0' diff --git a/core/modules/system/system.install b/core/modules/system/system.install index e938128..ac1aa94 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -2215,6 +2215,17 @@ function system_update_8032() { } /** + * Move the admin_compact_mode setting from variable to config. + * + * @ingroup config_upgrade + */ +function system_update_8033() { + update_variables_to_config('system.site', array( + 'admin_compact_mode' => 'admin_compact_mode', + )); +} + +/** * @} End of "defgroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 7f9f33a..2b06273 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -3363,7 +3363,7 @@ function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, function system_admin_compact_mode() { // PHP converts dots into underscores in cookie names to avoid problems with // its parser, so we use a converted cookie name. - return isset($_COOKIE['Drupal_visitor_admin_compact_mode']) ? $_COOKIE['Drupal_visitor_admin_compact_mode'] : variable_get('admin_compact_mode', FALSE); + return isset($_COOKIE['Drupal_visitor_admin_compact_mode']) ? $_COOKIE['Drupal_visitor_admin_compact_mode'] : config('system.site')->get('admin_compact_mode'); } /**