protected function Updater::updateConfig in Update helper 8
Same name and namespace in other branches
- 2.x src/Updater.php \Drupal\update_helper\Updater::updateConfig()
Update configuration.
It's possible to provide expected configuration that should be checked, before new configuration is applied in order to ensure existing configuration is expected one.
Parameters
string $config_name: Configuration name that should be updated.
array $update_actions: Configuration update actions.
array $expected_configuration: Only if current config is same like old config we are updating.
Return value
bool Returns TRUE if update of configuration was successful.
1 call to Updater::updateConfig()
- Updater::executeConfigurationActions in src/
Updater.php - Execute configuration update definitions for configurations.
File
- src/
Updater.php, line 351
Class
- Updater
- Helper class to update configuration.
Namespace
Drupal\update_helperCode
protected function updateConfig($config_name, array $update_actions, array $expected_configuration = []) {
$config = $this->configFactory
->getEditable($config_name);
$config_data = $config
->get();
// Check that configuration exists before executing update.
if (empty($config_data)) {
return FALSE;
}
// Apply configuration update actions.
$update_config_data = $this
->applyConfigActions($config_data, $update_actions);
// Check if configuration is already in new state.
if (empty(DiffArray::diffAssocRecursive($config_data, $update_config_data)) && empty(DiffArray::diffAssocRecursive($update_config_data, $config_data))) {
return TRUE;
}
if (!empty($expected_configuration) && DiffArray::diffAssocRecursive($expected_configuration, $config_data)) {
return FALSE;
}
$config
->setData($update_config_data);
$config
->save();
return TRUE;
}