Problem/Motivation

The user profile edit page, user/%uid/edit, has a field set for language settings and another one for locale settings. I don't think this is necessary and they should be joined together in one field set labeled 'Locale settings', because language and timezone are actually locale settings. So they should be joined in one field set to clean up the form a bit. This has been the case since Drupal 5.1, where at that time the system.module and locale.module each define their own field set on the user account settings page.

Proposed resolution

  • Create one field set for locale settings.
  • Locale setting also seems to be a really bad UX, Localization is a bit better at least and actually is more descriptive of what it does.

Remaining tasks

  • Review
  • Usability review
  • Commit
  • Enjoy!

User interface changes

Monolingual

Before:

Before Monolingual

After:

After Monolingual

Multilingual

Before:

Before Multilingual

After:

After Multilingual

API changes

Data model changes

CommentFileSizeAuthor
#59 afterpatch.png63.21 KBrinku jacob 13
#59 beforepatch.png53.86 KBrinku jacob 13
#58 interdiff-134209-55-57.txt2.48 KBmohit_aghera
#58 134209-57.patch7.75 KBmohit_aghera
#55 interdiff-134209-52-55.txt1.3 KBmohit_aghera
#55 134209-55.patch5.27 KBmohit_aghera
#52 interdiff-134209-46-52.txt1.62 KBmohit_aghera
#52 134209-52.patch6.57 KBmohit_aghera
#48 after_patch-multi.png51.24 KBguilhermevp
#48 after_patch-mono.png39.35 KBguilhermevp
#48 before_patch-multi.png52.04 KBguilhermevp
#48 before patch - monolingual.png56.25 KBguilhermevp
#46 interdiff-134209-33-45.txt1.56 KBmohit_aghera
#46 134209-45.patch8 KBmohit_aghera
#37 After-EditProfile-Multilingual.png45.47 KBquietone
#37 After-EditProfile.png35.52 KBquietone
#37 Before-EditProfile-Multilingual.png49.16 KBquietone
#37 Before-EditProfile.png35.25 KBquietone
#33 Screenshot_2021-02-24 v dev0-web.png25.78 KBquietone
#33 diff-23-33.txt10.42 KBquietone
#33 134209-33.patch6.86 KBquietone
#23 language-timezone-one-user-field-134209-23-interdiff.txt4.77 KBberdir
#23 language-timezone-one-user-field-134209-23.patch10.18 KBberdir
#19 language-timezone-one-user-field-134209-19-interdiff.txt966 bytesberdir
#19 language-timezone-one-user-field-134209-19.patch9.78 KBberdir
#18 language-timezone-one-user-field-134209-18.patch9.38 KBberdir
#14 language-timezone-one-user-field-134209-7255592.patch9.2 KBjohnennew
#13 Screen Shot 2013-04-04 at 09.27.26.png76.48 KBjohnennew
#11 language-timezone-one-user-field-134209-6295238.patch3.99 KBjohnennew
#5 locale_settings.patch2.37 KBpancho
locale_settings.patch2.02 KByojoe

Comments

yojoe’s picture

Category: task » feature
dries’s picture

I like this change.

(It makes you wonder though -- should the per-user timezone settings live in locale.module? I don't think so, but it's probably good to raise the question as people might find that more intuitive ...)

drumm’s picture

Version: 5.1 » 6.x-dev
Status: Needs review » Needs work

Features such as this will not go into the stable Drupal 5.x.

The patch no longer applies.

yojoe’s picture

Now that Drupal 6 approaches, I want to raise the question again, if this should be fixed?

pancho’s picture

Category: feature » task
StatusFileSize
new2.37 KB

Didn't apply anymore. Updated this patch to HEAD, although it's a bit late in D6 for this.

pancho’s picture

Status: Needs work » Needs review

Oops, forgot to set to CNR...

pancho’s picture

Dries said:

It makes you wonder though -- should the per-user timezone settings live in locale.module? I don't think so, but it's probably good to raise the question as people might find that more intuitive ...)

This should be discussed further as soon as we're in the D7 dev cycle.

Joining the two fieldsets on the user page would anyway make sense. So if someone could test and rtbc this patch...?

dpearcefl’s picture

Is this is an active need?

Status: Needs review » Needs work

The last submitted patch, locale_settings.patch, failed testing.

Robin Millette’s picture

Version: 6.x-dev » 8.x-dev
johnennew’s picture

Status: Needs work » Needs review
StatusFileSize
new3.99 KB

Please find an updated patch attached for review.

In Drupal 8.x, language fieldset is provided by the user module and locale is provided by the system module. The user module comes first so I changed it's language fieldset to be called locale with a title of 'Localization'.

System module then uses this fieldset.

Status: Needs review » Needs work

The last submitted patch, language-timezone-one-user-field-134209-6295238.patch, failed testing.

johnennew’s picture

Component: system.module » user.module
Assigned: Unassigned » johnennew
StatusFileSize
new76.48 KB

I'll look at updating the tests.

On reflection, why does the system module add the timezone selector to the user edit form. Although system module provides the timezone api functions, it should be the user module which adds the options to the user edit form. Since user and system are both core required modules for all Drupal sites I see no issue in moving all the options to the user module.

Next patch will include this.

See attached screenshot of what the combined fieldset looks like.

johnennew’s picture

Status: Needs work » Needs review
StatusFileSize
new9.2 KB

New patch attached for review. The patch moves the form elements for timezone out of the system module and puts it in the user module. The user module language form elements are placed inside a localization fieldset with the timezone element. This also corrects the openid module tests.

berdir’s picture

+++ b/core/modules/user/lib/Drupal/user/AccountFormController.php
@@ -178,18 +178,20 @@ public function form(array $form, array &$form_state, EntityInterface $account)
+    $localization_options_available = drupal_container()->get('module_handler')->moduleExists('language') || config('system.timezone')->get('user.configurable');

Can use $this->moduleHandler now. And should use Drupal::config().

berdir’s picture

Status: Needs review » Needs work

The last submitted patch, language-timezone-one-user-field-134209-7255592.patch, failed testing.

berdir’s picture

Title: Join language and timezone settings in one single fieldset » Join language and timezone settings in one single fieldset and move user code out of system.module
Version: 8.0.x-dev » 8.2.x-dev
Assigned: johnennew » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new9.38 KB

Wow, this is old :)

I guess this won't get into 8.1 and definitely not 8.0. Still would like to get rid of all those system/user form alters and hooks. Also pulling in some changes from #2051067: Move user timezone code from system.module form alters to user form controllers.

Also not sure if we need to keep system_user_timezone() and @deprecate it. I guess so, technically although nobody is hopefully calling it.

No interdiff since most of it didn't apply anymore.

berdir’s picture

Actually, that extra fields change makes no sense, we need to rename the existing one and just drop timezone.

The last submitted patch, 18: language-timezone-one-user-field-134209-18.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 19: language-timezone-one-user-field-134209-19.patch, failed testing.

dawehner’s picture

Issue summary: View changes
+++ b/core/modules/user/user.module
@@ -141,18 +141,11 @@ function user_entity_extra_field_info() {
-  $fields['user']['user']['form']['language'] = array(
-    'label' => t('Language settings'),
+  $fields['user']['user']['form']['localization'] = array(
+    'label' => t('Localization settings'),
     'description' => t('User module form element.'),

Would this require a hook_update_N call? Can't you move around the extra fields?

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new10.18 KB
new4.77 KB

Renamed the key back to language, makes this a smaller API change, also fixes the installer config test.

Improved the migrate test to actually set a default timezone which is always there in a non-kernel test. somehow ended up with a NULL vs. '' difference.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

quietone’s picture

Rerolled so I could make a screenshot to compare with the related issue.

jibran’s picture

Issue tags: +Needs usability review

I closed #272397: Update "Locale settings" on the user edit page to "Time zone settings" as a duplicate of this. This patch makes more than to me than the other issue. Let's ask for a usability review here.

aaronmchale’s picture

Status: Needs review » Needs work

Regarding usability review: Could we get some details under the User Interface Changes section of the Issue Summary, specifically before and after screenshots, thanks.

Also, IS references Drupal 5, might want to update that as well ;)

jibran’s picture

quietone’s picture

Issue summary: View changes
StatusFileSize
new35.25 KB
new49.16 KB
new35.52 KB
new45.47 KB
quietone’s picture

@AaronMcHale, thank you for the instructions.

I've updated the IS and added screenshots. I am hoping this is ready for a usability review now.

quietone’s picture

Status: Needs work » Needs review

Meant to set to NR.

berdir’s picture

+++ b/core/modules/user/src/AccountForm.php
@@ -279,29 +281,24 @@ public function form(array $form, FormStateInterface $form_state) {
     $system_date_config = \Drupal::config('system.date');
-    $form['timezone'] = [
-      '#type' => 'details',
-      '#title' => $this->t('Locale settings'),
-      '#open' => TRUE,
-      '#weight' => 6,
-      '#access' => $system_date_config->get('timezone.user.configurable'),
-    ];
     if ($self_register && $system_date_config->get('timezone.user.default') != UserInterface::TIMEZONE_SELECT) {

This means that we also need to remove the timezone key in user_entity_extra_field_info() and update all user form displays to remove that key from it.

This will break some customizations I suppose, but we did that before, form structures are not part of BC. That said, this being a separate extra field is slightly more complicated, as it might result in the timezone field showing up for sites that had hidden it through the form display but have language visible. As there is still the user configurable flag, I suppose that is only a very small amount of sites, but who knows.

Leaving at needs review as we can work on that after we have a +1 from a usability perspective.

aaronmchale’s picture

Issue summary: View changes

Fix some screenshot links.

benjifisher’s picture

Issue summary: View changes

I am updating the issue summary, showing the screenshots instead of providing links.

benjifisher’s picture

Issue summary: View changes
Issue tags: -Needs usability review

Usability review

We discussed this issue at #3200771: Drupal Usability Meeting 2021-03-05. In short, YES!

It is kind of silly to have three fieldsets or details elements (or even one or two) with just one form element each. While that will still be the case for monolingual sites (two fieldsets, each with one form element) this issue will improve the situation for multilingual sites.

We tried, but we could not think of any drawbacks.

Back to NW because of #40.

quietone’s picture

Status: Needs review » Needs work

@benjifisher and the UX team, thanks for the quick turnaround on this issue!

The next step is to do the work for #40.

This means that we also need to remove the timezone key in user_entity_extra_field_info() and update all user form displays to remove that key from it.

+++ b/core/modules/user/user.module
@@ -121,17 +121,11 @@ function user_entity_extra_field_info() {
-  if (\Drupal::config('system.date')->get('timezone.user.configurable')) {
-    $fields['user']['user']['form']['timezone'] = [
-      'label' => t('Timezone'),
-      'description' => t('System module form element.'),
-      'weight' => 6,
-    ];
-  }

This satisfies the first part, removing timezone fro user_entity_extra_field_info().

The second part is to update all user form displays to remove that key from it. How to do this? My knowledge of forms is pretty limited.

quietone’s picture

Issue tags: +Bug Smash Initiative

Adding Bug Smash tag because work on this started from the duplicate that was original a Bug Report.

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new8 KB
new1.56 KB

I think we need to remove language key from the entity_form display modes.

@Berdir, I found two occurrences for the same and removed in current patch.
Please correct me if I am missing something.

guilhermevp’s picture

Status: Needs review » Reviewed & tested by the community

Patch works as intended, while addressing #40. Since the propose is already revised I'm moving it to RTBC.

Edit: forgot to post image evidence. Adding below.

guilhermevp’s picture

StatusFileSize
new56.25 KB
new52.04 KB
new39.35 KB
new51.24 KB
catch’s picture

Title: Join language and timezone settings in one single fieldset and move user code out of system.module » Join language and timezone settings in one single fieldset

The second half of the issue title seems to be outdated, haven't reviewed the code properly yet but noticed no system.module changes.

catch’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/user/src/Entity/User.php
    @@ -108,6 +108,11 @@ public function preSave(EntityStorageInterface $storage) {
         }
    +
    +    $config = \Drupal::config('system.date');
    +    if ($config->get('timezone.user.configurable') && !$this->getTimeZone() && !$config->get('timezone.user.default')) {
    +      $this->timezone = $config->get('timezone.default');
    +    }
       }
    

    Why is this necessary? Presumably not due to the form changes?

  2. +++ b/core/modules/user/user.module
    @@ -121,17 +121,10 @@ function user_entity_extra_field_info() {
       ];
    -  if (\Drupal::config('system.date')->get('timezone.user.configurable')) {
    -    $fields['user']['user']['form']['timezone'] = [
    -      'label' => t('Timezone'),
    -      'description' => t('System module form element.'),
    -      'weight' => 6,
    -    ];
    -  }
    

    Will this require any form displays to be updated that could be referencing the extra field?

  3. +++ b/core/modules/user/user.module
    @@ -463,6 +456,19 @@ function user_login_finalize(UserInterface $account) {
    +
    +  $config = \Drupal::config('system.date');
    +  // If the user has a NULL time zone, notify them to set a time zone.
    +  if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) {
    +    \Drupal::messenger()
    +      ->addStatus(t('Configure your <a href=":user-edit">account time zone setting</a>.', [
    +        ':user-edit' => $account->url('edit-form', [
    +          'query' => \Drupal::destination()->getAsArray(),
    +          'fragment' => 'edit-timezone',
    +        ]),
    +      ]));
    +  }
    

    This looks like it's probably OK but again why is it done in this issue? Doesn't seem necessary for changing the fieldset.

  4. +++ b/core/profiles/demo_umami/config/install/core.entity_form_display.user.user.default.yml
    @@ -21,9 +21,6 @@ content:
         region: content
    -  timezone:
    -    weight: 6
    -    region: content
       user_picture:
    

    OK yeah this confirms the question above - so I think we probably need an update to remove timezone from every core.entity_form_display.user.user.*

berdir’s picture

+++ b/core/modules/user/user.module
@@ -463,6 +456,19 @@ function user_login_finalize(UserInterface $account) {
   \Drupal::service('session')->set('uid', $account->id());
+
+  $config = \Drupal::config('system.date');
+  // If the user has a NULL time zone, notify them to set a time zone.
+  if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) {
+    \Drupal::messenger()
+      ->addStatus(t('Configure your <a href=":user-edit">account time zone setting</a>.', [
+        ':user-edit' => $account->url('edit-form', [
+          'query' => \Drupal::destination()->getAsArray(),
+          'fragment' => 'edit-timezone',

this is likely a leftover from a reroll. Another issue moved this code from system.module to user.module and it added it to user_user_login(), so this would duplicate it.

And yeah, not sure about the migrate test changes.

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new6.57 KB
new1.62 KB

- Fixing suggestions #1 and #3
- For suggestion 2 and 4, I spotted two core.entity_form_display.user.user.default.yml files only.
Both the files are updated in patch #46

berdir’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserTest.php
@@ -34,6 +34,10 @@ protected function setUp(): void {
     $this->installEntitySchema('node');
     $this->installSchema('user', ['users_data']);
+    $this->installConfig(['system']);
+    $this->config('system.date')
+      ->set('timezone.default', 'Australia/Sydney')
+      ->save();
     // Make sure uid 1 is created.
     user_install();
 
@@ -105,7 +109,7 @@ public function testUser() {

@@ -105,7 +109,7 @@ public function testUser() {
       $this->assertSame($source->login, $user->getLastLoginTime());
       $is_blocked = $source->status == 0;
       $this->assertSame($is_blocked, $user->isBlocked());
-      $expected_timezone_name = $source->timezone_name ?: $this->config('system.date')->get('timezone.default');
+      $expected_timezone_name = $source->timezone_name ?: 'Australia/Sydney';
       $this->assertSame($expected_timezone_name, $user->getTimeZone());

I think this part is also safe to remove. It doesn't make any functional changes, I was able to remove any changes to the test and it still passes, so I think we should remove these changes too.

mohit_aghera’s picture

Assigned: Unassigned » mohit_aghera
mohit_aghera’s picture

Assigned: mohit_aghera » Unassigned
Status: Needs work » Needs review
StatusFileSize
new5.27 KB
new1.3 KB

Removing additional test cases.

@Berdir, do you think we should add functional tests? I think we are just changing form structure, so I thought of not to add.
Let me know if it makes sense.

berdir’s picture

Status: Needs review » Needs work

Hm, good question, but functionally, the wrappers have no effect as they have no #tree TRUE. So we are testing that each element works, just not that it visually appears within a given details element. But we don't have that for any existing element either I think, so I'd say that's not a requirement?

What we still do need is an update function to clean out remaining configuration. A post update that loads each user form display and removes the timezone component. See https://api.drupal.org/api/drupal/core%21modules%21system%21system.post_... for some examples that do stuff with form displays in updates.

I just checked, and the filled database dump has the timezone field enabled, so we just need to assert in a test then that it is no longer there. To see that, add var_dump(\Drupal::config('core.entity_form_display.user.user.default')->get()); to the end of \Drupal\Tests\system\Functional\UpdateSystem\UpdatePathTestBaseFilledTest, and then alter it to assert that the timezone key is no longer in there.

Also created a change record: https://www.drupal.org/node/3209248

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new7.75 KB
new2.48 KB

@Berdir Implemented following changes:
- Added an update hook to remove timezone from the configuration
- An test case to test the update hook process.
Test cases are passing on local.

rinku jacob 13’s picture

StatusFileSize
new53.86 KB
new63.21 KB

Verified and tested patch#58 on the drupal 9.3.x-dev version. Patch applied successfully and looks good to me.Adding screenshot for the reference.
Need +1 RTBC

longwave’s picture

+++ b/core/modules/user/src/AccountForm.php
@@ -279,29 +281,24 @@ public function form(array $form, FormStateInterface $form_state) {
     if ($self_register && $system_date_config->get('timezone.user.default') != UserInterface::TIMEZONE_SELECT) {
       $form['timezone']['#access'] = FALSE;
     }

$form['timezone'] no longer exists so this code needs updating or removing.

The logic around whether the fieldset is displayed or not and which type it is seems quite convoluted, are we sure that it is displayed correctly for all possible configurations?

berdir’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/src/AccountForm.php
@@ -279,29 +281,24 @@ public function form(array $form, FormStateInterface $form_state) {
-    ];
     if ($self_register && $system_date_config->get('timezone.user.default') != UserInterface::TIMEZONE_SELECT) {
       $form['timezone']['#access'] = FALSE;
     }
-    $form['timezone']['timezone'] = [
+    // Add the time zone field to the user edit and register forms.
+    $form['language']['timezone'] = [
       '#type' => 'select',
       '#title' => $this->t('Time zone'),
       '#default_value' => $account->getTimezone() ?: $system_date_config->get('timezone.default'),
       '#options' => system_time_zones($account->id() != $user->id(), TRUE),
       '#description' => $this->t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),
...
     ];

We did move the #access down. And the language field already depends on !$self_register.

But yes, we can remove that condition then.

Not 100% sure about about the new check vs. the explicit != TIMEZONE_SELECT check before. There is a third option, empty. I can actually not see any explicit usages of that, so not sure where that is used also confuses me as afaik we set a value then anyway in \user_user_presave. Anyway, I would propose to remove the if and keep the explicit == UserInterface::TIMEZONE_SELECT check then.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.