function socialblue_form_system_theme_settings_alter in Open Social 8.9
Same name and namespace in other branches
- 8 themes/socialblue/theme-settings.php \socialblue_form_system_theme_settings_alter()
- 8.2 themes/socialblue/theme-settings.php \socialblue_form_system_theme_settings_alter()
- 8.3 themes/socialblue/theme-settings.php \socialblue_form_system_theme_settings_alter()
- 8.4 themes/socialblue/theme-settings.php \socialblue_form_system_theme_settings_alter()
- 8.5 themes/socialblue/theme-settings.php \socialblue_form_system_theme_settings_alter()
- 8.6 themes/socialblue/theme-settings.php \socialblue_form_system_theme_settings_alter()
- 8.7 themes/socialblue/theme-settings.php \socialblue_form_system_theme_settings_alter()
- 8.8 themes/socialblue/theme-settings.php \socialblue_form_system_theme_settings_alter()
Implements hook_form_FORM_ID_alter().
File
- themes/
socialblue/ theme-settings.php, line 15 - Allows users to change the color scheme of themes.
Code
function socialblue_form_system_theme_settings_alter(&$form, FormStateInterface &$form_state, $form_id = NULL) {
// Work-around for a core bug affecting admin themes. See issue #943212.
if (isset($form_id)) {
return;
}
$theme = \Drupal::configFactory()
->get('system.theme')
->get('default');
// Check for the current active theme.
$active_theme = \Drupal::theme()
->getActiveTheme()
->getName();
// Check for the current default theme.
$system_theme_settings = \Drupal::configFactory()
->get('system.theme')
->get('default');
// If the default theme is either socialblue or socialsaas then extend
// the form in the appearance section.
if (array_key_exists('socialbase', \Drupal::service('theme.manager')
->getActiveTheme()
->getBaseThemes())) {
if ($active_theme == $system_theme_settings) {
$config = \Drupal::config($theme . '.settings');
$form['open_social_settings'] = [
'#type' => 'vertical_tabs',
'#title' => t('Opensocial settings'),
'#weight' => -50,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$form['os_color_settings'] = [
'#type' => 'details',
'#group' => 'open_social_settings',
'#title' => t('Border radius'),
'#weight' => 20,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$form['os_font_settings'] = [
'#type' => 'details',
'#group' => 'open_social_settings',
'#title' => t('Fonts'),
'#weight' => 10,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$form['os_color_settings']['card_radius'] = [
'#type' => 'number',
'#title' => t('Card border radius (px)'),
'#default_value' => $config
->get('card_radius'),
'#description' => t('Define the roundness of cards corners.'),
];
$form['os_color_settings']['form_control_radius'] = [
'#type' => 'number',
'#title' => t('Form control border radius (px)'),
'#default_value' => $config
->get('form_control_radius'),
'#description' => t('Define the roundness of the corners of form-controls, like <code>input</code>, <code>textarea</code> and <code>select</code>'),
];
$form['os_color_settings']['button_radius'] = [
'#type' => 'number',
'#title' => t('Button border radius (px)'),
'#default_value' => $config
->get('button_radius'),
'#description' => t('Define the roundness of buttons corners.'),
];
$form['os_email_settings'] = [
'#type' => 'details',
'#group' => 'open_social_settings',
'#title' => t('E-mail'),
'#weight' => 30,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$form['os_email_settings']['email_logo'] = [
'#type' => 'managed_file',
'#title' => t('Logo for e-mails'),
'#description' => t('Upload a logo which is shown in e-mail sent by the platform. This overrides the default logo that is also used in e-mails when no logo is provided here.'),
'#default_value' => $config
->get('email_logo'),
'#upload_location' => 'public://',
'#upload_validators' => [
'file_validate_is_image' => [],
'file_validate_extensions' => [
'gif png jpg jpeg',
],
],
];
// Ensure we save the file permanently.
$form['#submit'][] = 'socialblue_save_email_logo';
$form['os_hero_settings'] = [
'#type' => 'details',
'#group' => 'open_social_settings',
'#title' => t('Hero'),
'#weight' => 30,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$form['os_hero_settings']['hero_gradient_opacity'] = [
'#type' => 'range',
'#title' => t('Hero gradient'),
'#default_value' => $config
->get('hero_gradient_opacity'),
'#description' => t('Define the percentage of darkness of the hero gradient from 0 to 100.'),
'#min' => 0,
'#max' => 100,
];
// Font tab.
$fonts = [];
if (\Drupal::service('module_handler')
->moduleExists('social_font')) {
/** @var \Drupal\social_font\Entity\Font $font_entities */
foreach (Font::loadMultiple() as $font_entities) {
$fonts[$font_entities
->id()] = $font_entities
->get('name')->value;
}
}
$form['os_font_settings']['font_primary'] = [
'#type' => 'select',
'#title' => t('Font'),
'#options' => $fonts,
'#default_value' => $config
->get('font_primary'),
'#description' => t('The font family to use.'),
];
$form['os_style_settings'] = [
'#type' => 'details',
'#group' => 'open_social_settings',
'#title' => t('Style'),
'#weight' => 40,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#access' => \Drupal::currentUser()
->hasPermission('administer improved theme settings'),
];
$form['os_style_settings']['style'] = [
'#type' => 'select',
'#title' => t('Style'),
'#options' => [
'' => t('Default'),
'sky' => t('Sky (New)'),
],
'#default_value' => $config
->get('style'),
];
// When GIN is our admin theme, update the GIN colors.
if (\Drupal::configFactory()
->get('system.theme')
->get('admin') === 'gin') {
$form['#submit'][] = 'socialblue_update_gin_color_settings';
}
}
}
}