diff --git a/core/modules/user/lib/Drupal/user/AccountFormController.php b/core/modules/user/lib/Drupal/user/AccountFormController.php index 138b86e..d4580bd 100644 --- a/core/modules/user/lib/Drupal/user/AccountFormController.php +++ b/core/modules/user/lib/Drupal/user/AccountFormController.php @@ -2,19 +2,60 @@ /** * @file - * Definition of Drupal\user\AccountFormController. + * Contains \Drupal\user\AccountFormController. */ namespace Drupal\user; -use Drupal\Core\Entity\EntityFormControllerNG; +use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\Language; +use Drupal\Core\Language\LanguageManager; +use Drupal\Core\Entity\EntityControllerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the user account forms. */ -abstract class AccountFormController extends EntityFormControllerNG { - +abstract class AccountFormController extends EntityFormControllerNG implements EntityControllerInterface { + + /** + * The module handler to invoke hooks on. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManager + */ + protected $languageManager; + + /** + * Constructs a new EntityFormController object. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke hooks on. + * @param \Drupal\Core\Language\LanguageManager $language_manager + * The language manager. + */ + public function __construct(ModuleHandlerInterface $module_handler, LanguageManager $language_manager) { + $this->moduleHandler = $module_handler; + $this->languageManager = $language_manager; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $container->get('module_handler'), + $container->get('language_manager') + ); + } + /** * {@inheritdoc} */ @@ -185,7 +226,7 @@ public function form(array $form, array &$form_state) { include_once DRUPAL_ROOT . '/core/includes/language.inc'; $interface_language_is_default = language_negotiation_method_get_first(Language::TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_SELECTED; $form['language'] = array( - '#type' => language_multilingual() ? 'details' : 'container', + '#type' => $this->languageManager->isMultilingual() ? 'details' : 'container', '#title' => $this->t('Language settings'), // Display language selector when either creating a user on the admin // interface or editing a user account. @@ -200,14 +241,24 @@ public function form(array $form, array &$form_state) { '#description' => $interface_language_is_default ? $this->t("This account's preferred language for e-mails and site presentation.") : $this->t("This account's preferred language for e-mails."), ); + // 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 ($this->moduleHandler->moduleExists('language') && $this->languageManager->isMultilingual()) { + foreach (language_types_info() as $type_key => $language_type) { + $negotiation_settings = variable_get("language_negotiation_{$type_key}", array()); + if ($show_admin_language = isset($negotiation_settings[LANGUAGE_NEGOTIATION_USER_ADMIN])) { + break; + } + } + } $form['language']['preferred_admin_langcode'] = array( '#type' => 'language_select', '#title' => $this->t('Administration pages language'), '#languages' => Language::STATE_CONFIGURABLE, '#default_value' => $user_preferred_admin_langcode, - '#access' => user_access('access administration pages', $account), + '#access' => $show_admin_language && user_access('access administration pages', $account), ); - // User entities contain both a langcode property (for identifying the // language of the entity data) and a preferred_langcode property (see // above). Rather than provide a UI forcing the user to choose both