diff options
-rw-r--r-- | includes/common.inc | 30 | ||||
-rw-r--r-- | modules/user/user.module | 24 | ||||
-rw-r--r-- | modules/user/user.test | 15 |
3 files changed, 60 insertions, 9 deletions
diff --git a/includes/common.inc b/includes/common.inc index ecfd1a4a7..39c1ea14a 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -5421,6 +5421,36 @@ function element_children(&$elements, $sort = FALSE) { } /** + * Return the visibile children of an element. + * + * @param $elements + * The parent element. + * @return + * The array keys of the element's visible children. + */ +function element_get_visible_children(array $elements) { + $visible_children = array(); + + foreach (element_children($elements) as $key) { + $child = $elements[$key]; + + // Skip un-accessible children. + if (isset($child['#access']) && !$child['#access']) { + continue; + } + + // Skip value and hidden elements, since they are not rendered. + if (isset($child['#type']) && in_array($child['#type'], array('value', 'hidden'))) { + continue; + } + + $visible_children[$key] = $child; + } + + return array_keys($visible_children); +} + +/** * Provide theme registration for themes across .inc files. */ function drupal_common_theme() { diff --git a/modules/user/user.module b/modules/user/user.module index 745d4abd1..3361f06e9 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -3100,6 +3100,8 @@ function user_register_form($form, &$form_state) { $form['#attached']['library'][] = array('system', 'cookie'); $form['#attributes']['class'][] = 'user-info-from-cookie'; + $form['#pre_render'] = array('user_register_form_pre_render'); + // Start with the default user account fields. user_account_form($form, $form_state); @@ -3109,14 +3111,6 @@ function user_register_form($form, &$form_state) { $form_state['redirect'] = $_GET['q']; } - // If the "account" fieldset is the only element at the top level, its - // borders are hidden for aesthetic reasons. We do not remove the fieldset but - // preserve the form structure so that modules implementing - // hook_form_FORM_ID_alter() know where to find the basic elements. - if (count(element_children($form)) == 1) { - $form['account']['#type'] = 'markup'; - } - $form['submit'] = array( '#type' => 'submit', '#value' => t('Create new account'), @@ -3130,6 +3124,20 @@ function user_register_form($form, &$form_state) { } /** + * Form pre-render callback to clean up the user_register_form. + * + * If the "account" fieldset is the only element at the top level (apart from + * the submit button), its borders are hidden for aesthetic reasons. + */ +function user_register_form_pre_render($form) { + $visible_children = element_get_visible_children($form); + if (!count(array_diff($visible_children, array('account', 'submit')))) { + $form['account']['#theme_wrappers'] = array(); + } + return $form; +} + +/** * Submit handler for the user registration form. * * This function is shared by the installation form and the normal registration form, diff --git a/modules/user/user.test b/modules/user/user.test index e790c3ad7..323580eb3 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -111,12 +111,17 @@ class UserRegistrationTestCase extends DrupalWebTestCase { variable_set('configurable_timezones', 1); variable_set('date_default_timezone', 'Europe/Brussels'); + // Check that the account information fieldset's options are not displayed + // is a fieldset if there is not more than one fieldset in the form. + $this->drupalGet('user/register'); + $this->assertNoRaw('<fieldset id="edit-account"><legend>Account information</legend>', t('Account settings fieldset was hidden.')); + $edit = array(); $edit['name'] = $name = $this->randomName(); $edit['mail'] = $mail = $edit['name'] . '@example.com'; $edit['pass[pass1]'] = $new_pass = $this->randomName(); $edit['pass[pass2]'] = $new_pass; - $this->drupalPost('user/register', $edit, t('Create new account')); + $this->drupalPost(NULL, $edit, t('Create new account')); // Check user fields. $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail)); @@ -131,6 +136,14 @@ class UserRegistrationTestCase extends DrupalWebTestCase { $this->assertEqual($new_user->language, '', t('Correct language field.')); $this->assertEqual($new_user->picture, '', t('Correct picture field.')); $this->assertEqual($new_user->init, $mail, t('Correct init field.')); + + // Make the user timezone configurable, which will create a second fieldset + // on the registration page and cause the account information elements to + // be put in a fieldset. + variable_set('user_default_timezone', DRUPAL_USER_TIMEZONE_SELECT); + $this->drupalLogout(); + $this->drupalGet('user/register'); + $this->assertRaw('<fieldset id="edit-account"><legend>Account information</legend>', t('Account settings fieldset was not hidden.')); } } |