public static function ChartsDefaultSettings::transformLegacySettingsToNew in Charts 5.0.x
Same name and namespace in other branches
- 8.4 src/Settings/ChartsDefaultSettings.php \Drupal\charts\Settings\ChartsDefaultSettings::transformLegacySettingsToNew()
Transforms legacy settings to newer ones.
Parameters
array $old_settings: The old settings.
array $old_config_keys: The old settings keys.
Return value
array The new format settings.
5 calls to ChartsDefaultSettings::transformLegacySettingsToNew()
- ChartsDefaultSettings::getDefaults in src/
Settings/ ChartsDefaultSettings.php - Gets defaults settings.
- ChartsDefaultSettingsTest::testDefaults in tests/
src/ Unit/ Settings/ ChartsDefaultSettingsTest.php - Tests getter and setter for defaults.
- charts_blocks_update_8301 in modules/
charts_blocks/ charts_blocks.install - Move charts block settings in their own array tree under charts.
- charts_update_8301 in ./
charts.install - Update existing default config.
- charts_update_8302 in ./
charts.install - Update existing views to use the new chart settings.
File
- src/
Settings/ ChartsDefaultSettings.php, line 136
Class
- ChartsDefaultSettings
- The chart default settings instance.
Namespace
Drupal\charts\SettingsCode
public static function transformLegacySettingsToNew(array &$old_settings, array $old_config_keys = []) {
$new_settings = [];
$new_settings['fields']['stacking'] = !empty($old_settings['grouping']);
$old_config_keys = $old_config_keys ?: self::getLegacySettingsMappingKeys();
foreach ($old_settings as $setting_id => $setting_value) {
$setting_key_map = isset($old_config_keys[$setting_id]) ? $old_config_keys[$setting_id] : '';
if ($setting_key_map) {
$value = self::transformBoolStringValueToBool($setting_value);
// When a block setting belongs to the chart blocks we save it in a
// new setting.
if (substr($setting_key_map, 0, 7) === 'display') {
// Stripping the 'display_' in front of the mapping key.
$setting_key_map = substr($setting_key_map, 8, strlen($setting_key_map));
if (substr($setting_key_map, 0, 10) === 'dimensions') {
// Stripping dimensions_.
$setting_key_map = substr($setting_key_map, 11, strlen($setting_key_map));
$new_settings['display']['dimensions'][$setting_key_map] = $value;
}
elseif (substr($setting_key_map, 0, 5) === 'gauge') {
// Stripping gauge_.
$setting_key_map = substr($setting_key_map, 6, strlen($setting_key_map));
$new_settings['display']['gauge'][$setting_key_map] = $value;
}
else {
$new_settings['display'][$setting_key_map] = $value;
}
}
elseif (substr($setting_key_map, 0, 5) === 'xaxis') {
// Stripping xaxis_.
$setting_key_map = substr($setting_key_map, 6, strlen($setting_key_map));
$new_settings['xaxis'][$setting_key_map] = $value;
}
elseif (substr($setting_key_map, 0, 5) === 'yaxis') {
// Stripping yaxis_.
$setting_key_map = substr($setting_key_map, 6, strlen($setting_key_map));
if (substr($setting_key_map, 0, 9) === 'secondary') {
// Stripping gauge_.
$setting_key_map = substr($setting_key_map, 10, strlen($setting_key_map));
$new_settings['yaxis']['secondary'][$setting_key_map] = $value;
}
else {
$new_settings['yaxis'][$setting_key_map] = $value;
}
}
elseif (substr($setting_key_map, 0, 6) === 'fields') {
// Stripping fields_.
$setting_key_map = substr($setting_key_map, 7, strlen($setting_key_map));
if ($setting_key_map === 'data_providers' && is_array($value)) {
$data_providers = !empty($new_settings['fields']['data_providers']) ? $new_settings['fields']['data_providers'] : [];
if ($setting_id === 'data_fields' || $setting_id == 'field_colors') {
$new_settings['fields']['data_providers'] = self::getFieldsDataProviders($data_providers, $value);
}
}
else {
$new_settings['fields'][$setting_key_map] = $value;
}
}
elseif ($setting_key_map === 'grouping' && $new_settings['fields']['stacking']) {
$new_settings[$setting_key_map] = [];
}
else {
// We make sure that we handle the color unneeded array.
$new_settings[$setting_key_map] = $setting_key_map !== 'color' ? $value : $value[0];
}
// Then we remove it from the main old settings tree.
unset($old_settings[$setting_id]);
}
}
return $new_settings;
}