Problem/Motivation

The core "Account administration pages" negotiation method allows admin users (users with admin theme or admin page access) to configure their preferred admin language separate from their preferred site language. As this is stored on users, this could cause problems when enabled after install as existing users would not have this setting then. Even when enabled, new users default to have no preference.

There is the https://www.drupal.org/project/admin_user_language module to fix the shortcomings of core.

  1. It allows to force a site-wide admin default so it does not matter that much that users don't have it set up. (But it does it with saving the value into users which requires the user to be re-saved. This is not convenient.
  2. It also allows to set a different default from "no preference" for user accounts even if it allows the user to pick an option.

Steps to reproduce

Proposed resolution

Port the spirit of the functionality from https://www.drupal.org/project/admin_user_language to core but in a way that would be even more flexible and easier for the user:

  • Rename the core method to "Administration language" ("page" is removed as this is proposed to be used not only for whole pages but parts of pages in other issues, "Account' is removed due to the addition of a global default option)
  • Have settings directly on the method rather than a separate admin page
  • Introduce a global setting like the select box in the contrib module
  • Introduce a "Allow users to change this" option (which is the opposite of the "force" option from the module)
  • If users are not allowed to change this or don't have it customized, then fall back on the globally selected admin language within this method.
  • When the global default is changed, only apply this to new users created, don't bulk-update existing users.

Remaining tasks

Review. Implementation and tests are complete.

User interface changes

Before the MR

The negotiation method was confusingly named with a useless description and no options:

Users had a setting at all times but it was not explained what happens if they had no preference:


After the MR

New name for the negotiation method. Better description explaining the real purpose. Also config options added similar to other negotiation methods:

Settings under this option. Defaults to not allow user preference now and fall back on site default language. When this setting is used user forms don't get the setting.

User profile form setting previously had "- No preference -" as the option which did not explain what happens if that is set. Now it explains how and what it falls back to, so the user does not need to set it even if they are allowed to.

Introduced terminology

Administration language is either a globally set language for administering the site or a per user setting with a global default that is utilised if the dedicated language negotiation method is enabled.

API changes

None.

Data model changes

Settings are introduced for the admin pages negotiation method.

Release notes snippet

The language negotiation method formerly called "Account administration pages" is now "Administration language". This method was used for account based negotiation in the past. That is now an optional feature and is not enabled by default for new sites. (It is enabled for sites updating though). The negotiation method also offers a global setting for administration language.

When this method is enabled, administration interfaces will either show up in the user preferred admin language or fall back to the site level admin language configured here. If there is no user preferred admin language and an invalid site admin language is set (eg. that language is removed later), this method will return NULL and negotiation will fall back on further methods. Otherwise this method will be able to figure out the admin language by itself.

LLM disclosure

LLM was used to accelerate the development of this MR. Everything was hand-reviewed, scrutinised and corrected though.

Issue fork drupal-3607896

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gábor hojtsy created an issue. See original summary.

gábor hojtsy’s picture

Issue summary: View changes
gábor hojtsy’s picture

Issue summary: View changes
StatusFileSize
new267.9 KB
new202.52 KB

Adde screenshots of changed UI.

gábor hojtsy’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new115.19 KB

Pushed initial implementation to MR.

Adding one more screenshot.

Also add LLM disclosure.

gábor hojtsy’s picture

I realized we don't quite allow the user to change the admin language itself (of the site), we allow them to set their own. This actually allowed to simplify this setting UI more as we don't need to explain what the checkbox means when its label is correct :D

     $form['allow_user_change'] = [
       '#type' => 'checkbox',
-      '#title' => $this->t('Allow users to change the administration language'),
+      '#title' => $this->t('Allow users to set their own administration language'),
       '#default_value' => $config->get('admin_language.allow_user_change') ?? FALSE,
-      '#description' => $this->t('If checked, admins can set their own administration language preference on their account page.'),
    ];
needs-review-queue-bot’s picture

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

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

gábor hojtsy’s picture

I am further simplifying the help text on the config page so it is an easier read but also contains more accurate info at the same time :) \

-        $output = '<p>' . $this->t('The administration language applies to pages and interface elements that are accessible to users with the <em>Use the administration pages</em> or <em>View the administration theme</em> permission.') . '</p>';
+       $output = '<p>' . $this->t('Applies to administrative interfaces accessible to users with <em>Use the administration pages</em> or <em>View the administration theme</em> permission.') . '</p>';
gábor hojtsy’s picture

Issue summary: View changes
StatusFileSize
new240.67 KB

And a matching screenshot.

gábor hojtsy’s picture

Status: Needs work » Needs review

Test fails uncovered tests that just needed updating to cover the new situation. The test scenarios were there that we need just the results are now slightly different.

Also tests uncovered a performance regression introduced which can be resolved with different code ordering. I added a comment to the code to ensure that stays as-is (although performance tests would also flag it later if we change it).

This will be much closer to passing tests if not passing tests :D

gábor hojtsy’s picture

Now fully passes tests. The existing test coverage was actually very comprehensive, it is just that now the results are slightly different. There is a lack of fallback of language negotiation when on admin page, if the admin language negotiation method is set and it is an admin path then that decides it. I think that is intended. Otherwise the fallbacks are the same :)

So I think this is entirely complete with tests and all.

gábor hojtsy’s picture

Issue summary: View changes

Documented the behaviour in release notes snippet.

gábor hojtsy’s picture

Issue summary: View changes
StatusFileSize
new361.72 KB
new98.81 KB

Adding before screenshots for those not well versed in negotiation screens.

lauriii’s picture

+1 on the feature request + approach here 👍 Not super keen on the approach to reference the permissions in the UI. For some reason this feels foreign. Do we have other UIs where we describe behavior this way? Don't want to slow this down so I'd say it's better to land this as is than not to get anything changed.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

gábor hojtsy’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new156.15 KB

@lauriii: I don't feel strong about that description either, I think its more of a mistery what it applies to if we don't explain it but we did not explain it before either, so we don't necessarily need to explain it to introduce the site level default as well. Also adjusted the labels in the form a bit to make it simpler / more consistent and resolved a comment from @borisson_ and rebased on main :)

gábor hojtsy’s picture

One thing that I need to call out is that this improvement makes Drupal use the possibility to fall back from the admin language to other negotiation methods like path prefix. So before this MR it was possible to configure that the user can have an admin language but if they don't have one then the further methods worked (eg. you can view the admin site in any language based on the path prefix). After the current state of the MR if the negotiation method is enabled and the user does not have a preference, it always picks a specific language, does not fall back on eg. path prefix.

In other words if you want user preference for admin language then you can't have it without a site level certain value, while before this MR that was not certain and could still depend on path prefix for example. Should I add that feature back? (That would be an option to let the global select box define 'No global admin language' or something).

gábor hojtsy’s picture

After pondering more on this, I realized for sites updating we definitely don't want to disrupt them, so I added "back" the pre-MR behaviour of not necessarily having a global admin language. Issue summary needs update, but changes look good locally etc :)

gábor hojtsy’s picture

Following discussions with Lauri I rolled back the backwards compatible empty option for the default global admin language (which would have allowed to enable only user based preference and no global admin language preference, therefore would have fallen back to further negotiation methods). This also means the issue summary is up to date and is ready for reviews again.

If we want to make admin language more configurable or allow it to be more configurable, one option could be to add an "Administration language" negotiated thing where admins can prioritise options similar to how they can now for interface language and content language. Then admins can add arbitrary methods there. That may be overcomplicating things though. Creating a contrib module to be able to alter this would require swapping this negotiation method definition using hook_language_negotiation_info_alter, but is possible if the swap is one to one.

needs-review-queue-bot’s picture

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

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

gábor hojtsy’s picture

Status: Needs work » Needs review

Fixed remaining test issues to green. I think this is complete with the behaviour change explained :)

anjali rathod’s picture

Status: Needs review » Needs work
StatusFileSize
new429.88 KB

the patch initially failed to apply cleanly because of a stale hunk in OpenTelemetryAuthenticatedPerformanceTest.php. I excluded that file, applied the rest of the patch successfully, and tested multiple use cases. The functionality looks good from my testing.

gábor hojtsy’s picture

Status: Needs work » Needs review

Thanks for the review. Rebased MR is green again, applies cleanly now.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.