-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty "Region and language" fieldset on Registration page #6073
Comments
Looking at the code on $form['region_language'] = array(
'#type' => 'fieldset',
'#title' => t('Region and language'),
'#weight' => 6,
'#access' => (!$register && config_get('system.date', 'user_configurable_timezones')) || (module_exists('locale') && language_multilingual()),
'#group' => 'additional_settings',
);
// See system_user_timezone() and locale_language_selector_form() for the form
// items displayed here.
$register = ($form['#user']->uid > 0 ? FALSE : TRUE); That happens because the value of $config = config('system.date');
if ($config->get('user_configurable_timezones') && $config->get('user_default_timezone') == BACKDROP_USER_TIMEZONE_SELECT) {
system_user_timezone($form, $form_state);
} As for // Only alter user forms if there is more than one language.
if (language_multilingual()) {
// Display language selector when either creating a user on the admin
// interface or editing a user account.
if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
$selector = locale_language_selector_form($form['#user']);
$selector['locale']['#type'] = 'container';
$form['region_language'] += $selector;
if ($form_id == 'user_register_form') {
$form['region_language']['locale']['#access'] = user_access('administer users');
}
}
} The fix seems quite easy: Put in $form['region_language'] = array(
'#type' => 'fieldset',
'#title' => t('Region and language'),
'#weight' => 6,
'#access' => (!$register && config_get('system.date', 'user_configurable_timezones')) && config_get('system.date', 'user_default_timezone') == BACKDROP_USER_TIMEZONE_SELECT || (module_exists('locale') && language_multilingual()),
'#group' => 'additional_settings',
);
// See system_user_timezone() and locale_language_selector_form() for the form
// items displayed here. |
(Let's wait tests run.) |
Actually, for the language form elements to be shown, it should be sufficient that |
As a side note, if I do not install the Locale and the Language modules, the registration form doesn't allow users to select a timezone. The same happens when the Locale and the Language modules are installed, but no language is added. I am not sure this is expected. A site could not need to be localized, but users should still be able to select their timezone, if the Users may set their own time zone setting has been selected. |
Many thanks for the PR, @kiamlaluno ! Looks good on the sandbox site, works for me. |
Oh, wait: After disabling the option "Users may set their own time zone" on |
Working with a multilanguage site: Without the patch:
After applying the patch:
So the PR doesn't solve the original problem, and unfortunately, it creates a new problem. BTW: don't forget to clear caches every time you make a change. Anonymous users see cached pages otherwise, so your testing may give you false positives or negatives. |
The issue is that what The effect is that the fieldset is added, but no form element is added to that fieldset. |
To make a summary:
|
Is the Region and language fieldset supposed to appear (with the form element to select a timezone) when a person registers an account? |
Good question. I don't recall seeing the element, but most of my sites aren't even open for visitor registration, so I'm not sure. |
I will check what happens when I register a new account on d.org, which uses Drupal 7. If then it does not appear on d.org, I will check what code is used from Drupal 7. (I forgot to add not on the previous sentence. 😅) |
(And since I can see the user settings on d.org, I can also verify if that happens because how the site has been set.) |
Interesting, when I disable the Locale module, the issue is gone.
|
Okay, let's see: Maybe the issue was introduced when Backdrop added vertical tabs to the user account form (related: #5747) with version 1.23.0. I've just downgraded one of my test sites to Backdrop 1.22.2, and there I can't reproduce the issue. |
On Drupal 7 the Region and language fieldset is not shown because |
The issue is definitively in In fact, when I would change the code to match the Drupal 7 code, but I would like to understand why Backdrop uses that code. (I forgot some parentheses in the code.) |
Finally, this is the code for Drupal 7 function system_form_user_register_form_alter(&$form, &$form_state) {
if (variable_get('configurable_timezones', 1)) {
if (variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) == DRUPAL_USER_TIMEZONE_SELECT) {
system_user_timezone($form, $form_state);
}
else {
$form['account']['timezone'] = array(
'#type' => 'hidden',
'#value' => variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) ? '' : variable_get('date_default_timezone', ''),
);
}
return $form;
}
} function locale_form_alter(&$form, &$form_state, $form_id) {
// Only alter user forms if there is more than one language.
if (drupal_multilingual()) {
// Display language selector when either creating a user on the admin
// interface or editing a user account.
if ($form_id == 'user_register_form' || $form_id == 'user_profile_form' && $form['#user_category'] == 'account') {
locale_language_selector_form($form, $form_state, $form['#user']);
}
}
}
|
For the (The site seems to suggest |
The test that fails is // Check if the language selector is available on admin/people/create and
// set to the currently active language.
$this->backdropGet($langcode . '/admin/people/create');
$this->assertFieldChecked("edit-language-$langcode", 'Global language set in the language selector.'); |
No, $form['#user'] = entity_create('user', array());
It seems that the code should check the currently logged-in user. If its user ID is zero, then is a visitor who is registering an account; if the user ID is not zero, it must be an administrator user who is creating an account (or somebody is editing an existing account). |
Now tests are failing because connection time-outs.
|
The standard behavior for visiting The only way for administrators to create accounts is to visit |
Administrator users do not visit user/register to create an account. They just get the same form when they visit admin/people/create. $items['admin/people/create'] = array(
'title' => 'Add user account',
'page callback' => 'backdrop_get_form',
'page arguments' => array('user_register_form'),
'access arguments' => array('administer users'),
'type' => MENU_LOCAL_ACTION,
);
$form['#user'] = entity_create('user', array());
$form['#attached']['library'][] = array('system', 'jquery.cookie');
$form['#attributes']['class'][] = 'user-info-from-cookie';
// Start with the default user account fields.
user_account_form($form, $form_state);
|
Between 9 hours, I will close and re-open the PR to let the tests start again. (It is past midnight for me.) |
All tests pass. |
@kiamlaluno Thanks for the updated PR! I've tested the sandbox site with the 'Steps to reproduce', and the fix works for me: The (empty) "Region and language" fieldset on the "Create new account" page isn't there anymore. For curiosity: Do you think the issue was introduced when Backdrop 1.23.0 added vertical tabs to the user account form in #3872 and #5747? Or became it just visible then, or is it not related at all? |
@olafgrabienski I would say they were "fooled" by the variable name as I was. I thought that That variable name has been inherited from Drupal 7; the only difference in Drupal 7 is that |
Thanks @kiamlaluno I may be misunderstanding what you are trying to do or what is the expected behavior, but this is what I'm seeing now:
Now, I'm logging out and going to I don't see the fieldset that allows me to set up my timezone at registration This behavior, to me, sounds very confusing. I expressly selected "Users may set their own time zone at registration" yet I'm not able to set my timezone. Can you let me know what I'm missing? |
Oh, sorry, I forgot to test the "Users may set their own time zone at registration" setting. |
I apologize: It is me who forgot what already said about that setting. I need to add a condition more in the |
The preview site shows the Region and language fieldset with the timezone selector to visitors who want to register an account. I set the preview site to avoid caching pages for anonymous users. User #ㅤ1 see that fieldset too. When Users may set their own time zone is not selected, visitors who register an account are not allowed to set their time zone. ㅤUser #ㅤ1 still see the fieldset when creating an account. |
Tests passes. |
Thanks for another PR update! Works for me in the sandbox, including the different behavior depending on the "Users may set their own time zone at registration" setting. |
Hi @kiamlaluno Thanks so much again... but sorry to keep going back to this issue, but there are still several inconsistencies. I think this may be due in part to lack of clarity in the current configuration UI. Specifically, in I'm basing this functionality on the behavior in Drupal 7, which I believe does it correctly, and its behavior clarifies the meaning of those options. I'm looking ONLY at the new user registration form, and ONLY when "Users may set their own time zone." is selected. Everything else works fine In DRUPAL 7 (having selected "Users may set their own time zone."):
So, with your patch, unfortunately, the Time Zone selection is shown for ALL three options listed above. This is incorrect. So, to me, this needs work. And perhaps we can clarify the UI to indicate that these 3 options ONLY apply to the New User Registration form, for example: Time zone in new user registration form: |
I am not able to change the code and avoid tests fail. |
To give more details:
|
Description of the bug
On localized Backdrop sites where visitors are allowed to register user accounts, there is an empty "Region and language" fieldset on the page "Create new account".
Steps To Reproduce
To reproduce the behavior:
admin/config/regional/language
.admin/config/people/settings
.user/register
).Actual behavior
There is an empty "Region and language" fieldset above the "Create new account" button.
(See screenshot below.)
Expected behavior
No "Region and language" fieldset.
Additional info
Backdrop CMS version: 1.24.2 (Tugboat demo)
Screenshot:

The text was updated successfully, but these errors were encountered: