Skip to content
Snippets Groups Projects
Commit 2f927f14 authored by Steven Wittens's avatar Steven Wittens
Browse files

#58330: Fix inconsistent theme selector code

parent fb580ade
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -168,16 +168,53 @@ function system_test_clean_url($form_id) { ...@@ -168,16 +168,53 @@ function system_test_clean_url($form_id) {
*/ */
function system_user($type, $edit, &$user, $category = NULL) { function system_user($type, $edit, &$user, $category = NULL) {
if ($type == 'form' && $category == 'account') { if ($type == 'form' && $category == 'account') {
$form['theme_select'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the site.'), $edit['theme'], 2);
if (variable_get('configurable_timezones', 1)) {
$zones = _system_zonelist();
$form['timezone'] = array('#type'=>'fieldset', '#title' => t('Locale settings'), '#weight' => 6);
$form['timezone']['timezone'] = array(
'#type' => 'select', '#title' => t('Time zone'), '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
'#options' => $zones, '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
);
}
return $form;
}
}
/*
* Returns a fieldset containing the theme select form.
*
* @param $description
* description of the fieldset
* @param $default_value
* default value of theme radios
* @param $weight
* weight of the fieldset
* @return
* a form array
*/
function system_theme_select_form($description = '', $default_value = '', $weight = 0) {
if (user_access('select different theme')) { if (user_access('select different theme')) {
$themes = array_filter(list_themes(), create_function('$theme', 'return $theme->status;')); foreach (list_themes() as $theme) {
if ($theme->status) {
$enabled[] = $theme;
}
}
if (count($themes) > 1) { if (count($enabled) > 1) {
ksort($themes); ksort($enabled);
$form['themes'] = array( $form['themes'] = array(
'#type' => 'fieldset', '#title' => t('Theme configuration'), '#description' => t('Selecting a different theme will change the look and feel of the site.'), '#weight' => 2, '#collapsible' => TRUE, '#theme' => 'system_user'); '#type' => 'fieldset',
'#title' => t('Theme configuration'),
'#description' => $description,
'#collapsible' => TRUE,
'#theme' => 'system_theme_select_form'
);
foreach ($themes as $info) { foreach ($enabled as $info) {
// For the default theme, revert to an empty string so the user's theme updates when the site theme is changed. // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed.
$info->key = $info->name == variable_get('theme_default', 'bluemarine') ? '' : $info->name; $info->key = $info->name == variable_get('theme_default', 'bluemarine') ? '' : $info->name;
...@@ -189,23 +226,14 @@ function system_user($type, $edit, &$user, $category = NULL) { ...@@ -189,23 +226,14 @@ function system_user($type, $edit, &$user, $category = NULL) {
$options[$info->key] = ''; $options[$info->key] = '';
} }
$form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $edit['theme'] ? $edit['theme'] : ''); $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : '');
} $form['#weight'] = $weight;
}
if (variable_get('configurable_timezones', 1)) {
$zones = _system_zonelist();
$form['timezone'] = array('#type'=>'fieldset', '#title' => t('Locale settings'), '#weight' => 6);
$form['timezone']['timezone'] = array(
'#type' => 'select', '#title' => t('Time zone'), '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
'#options' => $zones, '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
);
}
return $form; return $form;
} }
} }
}
function theme_system_user($form) { function theme_system_theme_select_form($form) {
foreach (element_children($form) as $key) { foreach (element_children($form) as $key) {
$row = array(); $row = array();
if (is_array($form[$key]['description'])) { if (is_array($form[$key]['description'])) {
......
...@@ -168,16 +168,53 @@ function system_test_clean_url($form_id) { ...@@ -168,16 +168,53 @@ function system_test_clean_url($form_id) {
*/ */
function system_user($type, $edit, &$user, $category = NULL) { function system_user($type, $edit, &$user, $category = NULL) {
if ($type == 'form' && $category == 'account') { if ($type == 'form' && $category == 'account') {
$form['theme_select'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the site.'), $edit['theme'], 2);
if (variable_get('configurable_timezones', 1)) {
$zones = _system_zonelist();
$form['timezone'] = array('#type'=>'fieldset', '#title' => t('Locale settings'), '#weight' => 6);
$form['timezone']['timezone'] = array(
'#type' => 'select', '#title' => t('Time zone'), '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
'#options' => $zones, '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
);
}
return $form;
}
}
/*
* Returns a fieldset containing the theme select form.
*
* @param $description
* description of the fieldset
* @param $default_value
* default value of theme radios
* @param $weight
* weight of the fieldset
* @return
* a form array
*/
function system_theme_select_form($description = '', $default_value = '', $weight = 0) {
if (user_access('select different theme')) { if (user_access('select different theme')) {
$themes = array_filter(list_themes(), create_function('$theme', 'return $theme->status;')); foreach (list_themes() as $theme) {
if ($theme->status) {
$enabled[] = $theme;
}
}
if (count($themes) > 1) { if (count($enabled) > 1) {
ksort($themes); ksort($enabled);
$form['themes'] = array( $form['themes'] = array(
'#type' => 'fieldset', '#title' => t('Theme configuration'), '#description' => t('Selecting a different theme will change the look and feel of the site.'), '#weight' => 2, '#collapsible' => TRUE, '#theme' => 'system_user'); '#type' => 'fieldset',
'#title' => t('Theme configuration'),
'#description' => $description,
'#collapsible' => TRUE,
'#theme' => 'system_theme_select_form'
);
foreach ($themes as $info) { foreach ($enabled as $info) {
// For the default theme, revert to an empty string so the user's theme updates when the site theme is changed. // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed.
$info->key = $info->name == variable_get('theme_default', 'bluemarine') ? '' : $info->name; $info->key = $info->name == variable_get('theme_default', 'bluemarine') ? '' : $info->name;
...@@ -189,23 +226,14 @@ function system_user($type, $edit, &$user, $category = NULL) { ...@@ -189,23 +226,14 @@ function system_user($type, $edit, &$user, $category = NULL) {
$options[$info->key] = ''; $options[$info->key] = '';
} }
$form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $edit['theme'] ? $edit['theme'] : ''); $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : '');
} $form['#weight'] = $weight;
}
if (variable_get('configurable_timezones', 1)) {
$zones = _system_zonelist();
$form['timezone'] = array('#type'=>'fieldset', '#title' => t('Locale settings'), '#weight' => 6);
$form['timezone']['timezone'] = array(
'#type' => 'select', '#title' => t('Time zone'), '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
'#options' => $zones, '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
);
}
return $form; return $form;
} }
} }
}
function theme_system_user($form) { function theme_system_theme_select_form($form) {
foreach (element_children($form) as $key) { foreach (element_children($form) as $key) {
$row = array(); $row = array();
if (is_array($form[$key]['description'])) { if (is_array($form[$key]['description'])) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment