getPreferredAdminLangcode example

/** * {@inheritdoc} */
  public function getPreferredLangcode($fallback_to_default = TRUE) {
    return $this->getAccount()->getPreferredLangcode($fallback_to_default);
  }

  /** * {@inheritdoc} */
  public function getPreferredAdminLangcode($fallback_to_default = TRUE) {
    return $this->getAccount()->getPreferredAdminLangcode($fallback_to_default);
  }

  /** * {@inheritdoc} */
  public function getAccountName() {
    return $this->getAccount()->getAccountName();
  }

  /** * {@inheritdoc} */
'#disabled' => TRUE,
    ];

    $form['account']['notify'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Notify user of new account'),
      '#access' => $admin_create,
    ];

    $user_preferred_langcode = $register ? $language_interface->getId() : $account->getPreferredLangcode();

    $user_preferred_admin_langcode = $register ? $language_interface->getId() : $account->getPreferredAdminLangcode(FALSE);

    // Is the user preferred language added?     $user_language_added = FALSE;
    if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
      $negotiator = $this->languageManager->getNegotiator();
      $user_language_added = $negotiator && $negotiator->isNegotiationMethodEnabled(LanguageNegotiationUser::METHOD_ID, LanguageInterface::TYPE_INTERFACE);
    }
    $form['language'] = [
      '#type' => $this->languageManager->isMultilingual() ? 'details' : 'container',
      '#title' => $this->t('Language settings'),
      '#open' => TRUE,
      
$container->get('current_route_match')
    );
  }

  /** * {@inheritdoc} */
  public function getLangcode(Request $request = NULL) {
    $langcode = NULL;

    // User preference (only for administrators).     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;
    }

    // Not an admin, no admin language preference or not on an admin path.     return $langcode;
  }

  /** * Checks whether the given path is an administrative one. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * * @return bool * TRUE if the path is administrative, FALSE otherwise. */
Home | Imprint | This part of the site doesn't use cookies.