function improved_theme_settings_update_8001 in Open Social 10.1.x
Same name and namespace in other branches
- 8.9 modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 8 modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 8.2 modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 8.3 modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 8.4 modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 8.5 modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 8.6 modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 8.7 modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 8.8 modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 10.3.x modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 10.0.x modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
- 10.2.x modules/custom/improved_theme_settings/improved_theme_settings.install \improved_theme_settings_update_8001()
Migrate old theme settings to the new settings.
File
- modules/
custom/ improved_theme_settings/ improved_theme_settings.install, line 21 - Improved theme settings module install file.
Code
function improved_theme_settings_update_8001() {
// Get the current default theme.
$theme = \Drupal::configFactory()
->get('system.theme')
->get('default');
// Get the color values.
$config = \Drupal::configFactory()
->getEditable('color.theme.' . $theme);
$colors = $config
->getRawData();
// Create an array for the new color values.
$new_colors = [
'brand-primary' => '#29abe2',
'brand-secondary' => '#1f80aa',
'brand-accent' => '#ffc142',
'brand-link' => '#33b5e5',
'navbar-bg' => '#333333',
'navbar-text' => '#ffffff',
'navbar-active-bg' => '#1f1f1f',
'navbar-active-text' => '#f3f3f3',
'navbar-sec-bg' => '#1f7ea7',
'navbar-sec-text' => '#f9f9f9',
];
// Fetch values from the old theme and overrode em.
if (isset($colors['palette']['brand-bg-primary'])) {
$new_colors['brand-primary'] = $colors['palette']['brand-bg-primary'];
}
if (isset($colors['palette']['brand-bg-secondary'])) {
$new_colors['brand-secondary'] = $colors['palette']['brand-bg-secondary'];
}
if (isset($colors['palette']['brand-bg-accent'])) {
$new_colors['brand-accent'] = $colors['palette']['brand-bg-accent'];
}
if (isset($colors['palette']['brand-text-primary'])) {
$new_colors['brand-link'] = $colors['palette']['brand-text-primary'];
}
// overwrite.
$colors['palette'] = $new_colors;
// Save the new config.
$config
->setData($colors)
->save();
}