public static function ArrayConfig::mergeDefaults in Little helpers 7.2
Same name and namespace in other branches
- 7 src/ArrayConfig.php \Drupal\little_helpers\ArrayConfig::mergeDefaults()
Helper functions that recursively merges $defaults into a $config array.
In general it tries to do the right thing: Associative arrays are merged except when they look like checkbox values.
Parameters
array &$config: A config array to merge the defaults into.
array $defaults: The defaults array.
1 call to ArrayConfig::mergeDefaults()
- ArrayConfigTest::testMergeDefaults in tests/
ArrayConfigTest.php - Test various different kinds of config default configurations.
File
- src/
ArrayConfig.php, line 48
Class
- ArrayConfig
- Helper functions to manage configuration stored in arrays.
Namespace
Drupal\little_helpersCode
public static function mergeDefaults(array &$config, array $defaults) {
$config += $defaults;
foreach ($config as $key => $value) {
if (is_array($value) && isset($defaults[$key]) && is_array($defaults[$key])) {
if (!$value && static::isMergable($defaults[$key]) || static::isMergable($value)) {
self::mergeDefaults($config[$key], $defaults[$key]);
}
}
}
}