function social_core_update_8902 in Open Social 10.2.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_core/social_core.install \social_core_update_8902()
- 10.3.x modules/social_features/social_core/social_core.install \social_core_update_8902()
- 10.0.x modules/social_features/social_core/social_core.install \social_core_update_8902()
- 10.1.x modules/social_features/social_core/social_core.install \social_core_update_8902()
Update GIN theme settings based on SocialBlue primary secondary.
File
- modules/
social_features/ social_core/ social_core.install, line 1207 - Install, update and uninstall functions for the social_core module.
Code
function social_core_update_8902() {
// Only when GIN is the admin theme and SocialBlue is the active theme.
if (\Drupal::configFactory()
->get('system.theme')
->get('admin') === 'gin' && \Drupal::theme()
->getActiveTheme()
->getName() === 'socialblue') {
// Grab the default socialblue colors, these are set if the color settings
// aren't overridden yet.
$default_colors = \Drupal::configFactory()
->getEditable('socialblue.settings')
->getRawData();
// Unfortunately the color module doesnt add the color details to the
// $form_state. So we need to grab it from the config once overridden.
// luckily color does set their submit function as first, so we can
// safely assume the config uses the updated colors.
$socialblue_colors = \Drupal::configFactory()
->getEditable('color.theme.socialblue')
->getRawData();
// The brand colors are first of all coming from the overridden color
// settings. But if that is not set, we will grab them from the
// default Social Blue settings.
$brand_primary = !empty($socialblue_colors) ? $socialblue_colors['palette']['brand-primary'] : $default_colors['color_primary'];
$brand_secondary = !empty($socialblue_colors) ? $socialblue_colors['palette']['brand-secondary'] : $default_colors['color_secondary'];
// See if we can update GIN settings with our brand colors.
if (isset($brand_primary, $brand_secondary)) {
$config = \Drupal::configFactory()
->getEditable('gin.settings');
if (!empty($config
->getRawData())) {
$gin_config = $config
->getRawData();
// Override preset colors as custom so we can fill in the hex colors.
$gin_config['preset_accent_color'] = 'custom';
$gin_config['preset_focus_color'] = 'custom';
// Update the accent and focus with our branded colors.
$gin_config['accent_color'] = $brand_primary;
$gin_config['focus_color'] = $brand_secondary;
$config
->setData($gin_config);
$config
->save();
}
}
}
}