Commit 11b98e4f authored by webchick's avatar webchick
Browse files

#637712 by c960657 and Dave Reid: Fixed Fieldset is back in user registration form.

parent 4335a60b
......@@ -5420,6 +5420,36 @@ function element_children(&$elements, $sort = FALSE) {
return array_keys($children);
}
/**
* 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.
*/
......
......@@ -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'),
......@@ -3129,6 +3123,20 @@ function user_register_form($form, &$form_state) {
return $form;
}
/**
* 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.
*
......
......@@ -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.'));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment