function charts_highcharts_update_8400 in Charts 8.4
Same name and namespace in other branches
- 5.0.x modules/charts_highcharts/charts_highcharts.install \charts_highcharts_update_8400()
Move the highcharts config to the main settings and plugin configuration.
File
- modules/
charts_highcharts/ charts_highcharts.install, line 32 - Installation and update hooks for the Charts Highcharts module.
Code
function charts_highcharts_update_8400() {
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = \Drupal::service('config.factory');
$highcharts_config = $config_factory
->getEditable('charts_highcharts.settings');
$config_keys = [
'legend_layout',
'legend_background_color',
'legend_border_width',
'legend_shadow',
'item_style_color',
'text_overflow',
];
$legend_configuration = [];
foreach ($config_keys as $key) {
if ($config_value = $highcharts_config
->get($key)) {
$config_value = ChartsDefaultSettings::transformBoolStringValueToBool($config_value);
if (substr($key, 0, 6) === 'legend') {
// Stripping legend_.
$new_key_map = substr($key, 7, strlen($key));
$legend_configuration[$new_key_map] = $config_value;
}
elseif ($key === 'item_style_color') {
$legend_configuration['item_style']['color'] = $config_value;
}
elseif ($key === 'text_overflow') {
$config_value = $config_value ?: '';
$legend_configuration['item_style']['text_overflow'] = $config_value;
}
}
}
if ($legend_configuration) {
$library_form = 'highcharts_settings';
// Get the main settings.
$charts_config = $config_factory
->getEditable('charts.settings');
$settings = $charts_config
->get('charts_default_settings') ?: [];
// Add the plugin configuration as part of it.
$settings[$library_form]['legend'] = $legend_configuration;
// Update the main config.
$charts_config
->set('charts_default_settings', $settings)
->save();
// Delete the highcharts configuration.
$highcharts_config
->delete();
}
}