Unverified Commit 8466fbc9 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3007288 by yongt9412, mbovan, Berdir: LanguageNegotiationUserAdmin...

Issue #3007288 by yongt9412, mbovan, Berdir: LanguageNegotiationUserAdmin requires 'access administration pages' which is too strict
parent 07e9abde
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -252,7 +252,7 @@ public function form(array $form, FormStateInterface $form_state) {
    // Only show the account setting for Administration pages language to users
    // if one of the detection and selection methods uses it.
    $show_admin_language = FALSE;
    if ($account->hasPermission('access administration pages') && $this->languageManager instanceof ConfigurableLanguageManagerInterface) {
    if (($account->hasPermission('access administration pages') || $account->hasPermission('view the administration theme')) && $this->languageManager instanceof ConfigurableLanguageManagerInterface) {
      $negotiator = $this->languageManager->getNegotiator();
      $show_admin_language = $negotiator && $negotiator->isNegotiationMethodEnabled(LanguageNegotiationUserAdmin::METHOD_ID);
    }
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public function getLangcode(Request $request = NULL) {
    $langcode = NULL;

    // User preference (only for administrators).
    if ($this->currentUser->hasPermission('access administration pages') && ($preferred_admin_langcode = $this->currentUser->getPreferredAdminLangcode(FALSE)) && $this->isAdminPath($request)) {
    if (($this->currentUser->hasPermission('access administration pages') || $this->currentUser->hasPermission('view the administration theme')) && ($preferred_admin_langcode = $this->currentUser->getPreferredAdminLangcode(FALSE)) && $this->isAdminPath($request)) {
      $langcode = $preferred_admin_langcode;
    }

+10 −2
Original line number Diff line number Diff line
@@ -81,8 +81,9 @@ public function testUserAdminLanguageConfigurationAvailableWithAdminLanguageNego
  /**
   * Tests that the admin language is configurable only for administrators.
   *
   * If a user has the permission "access administration pages", they should
   * be able to see the setting to pick the language they want those pages in.
   * If a user has the permission "access administration pages" or
   * "view the administration theme", they should be able to see the setting to
   * pick the language they want those pages in.
   *
   * If a user does not have that permission, it would confusing for them to
   * have a setting for pages they cannot access, so they should not be able to
@@ -98,6 +99,13 @@ public function testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegoti
    // Ensure administration pages language setting is visible for admin.
    $this->assertFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector available for admins.');

    // Ensure administration pages language setting is visible for editors.
    $editor = $this->drupalCreateUser(['view the administration theme']);
    $this->drupalLogin($editor);
    $path = 'user/' . $editor->id() . '/edit';
    $this->drupalGet($path);
    $this->assertFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector available for editors.');

    // Ensure administration pages language setting is hidden for non-admins.
    $this->drupalLogin($this->regularUser);
    $path = 'user/' . $this->regularUser->id() . '/edit';