diff --git a/core/includes/config.inc b/core/includes/config.inc index 522abbd..6652df7 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -71,15 +71,25 @@ function config($name) { /** * Retrieves a configuration object for administration. * - * This configuration object has a special configuration context (admin = TRUE) - * and configuration plug-ins should mostly keep hands off this object and don't - * override it. + * This configuration object will be created using a special configuration + * context (config.admin = TRUE) and configuration plug-ins should mostly keep + * hands off it and don't override it. + * + * This is intended for administration forms or any other case when we need to + * get / set the configuration data without any overrides, as oppossed to + * regular configuration used for runtime operations that may be altered by + * plug-ins depending on other page request parameters: + * + * To get regular configuration objects for the page request use config() + * instead of this function. * * @param $name * The name of the configuration object to retrieve. * * @return Drupal\Core\Config\Config * A configuration object. + * + * @see config() */ function config_admin($name) { static $config_factory; @@ -92,6 +102,17 @@ function config_admin($name) { /** * Retrieves a configuration factory object for a given context. * + * A configuration context is an array of parameters that are available to the + * configuration plug-ins for them to customize the configuration data in + * different ways. Examples of parameters used by Drupal core are: + * - 'user.account', to get configuration that may be localized for a user. + * - 'config.admin', TRUE to get configuration data without further + * customizations for administration purposes. + * + * Modules can add any other parameter or provide plug-ins that react to + * specific context parameters. In order to avoid conflicts the parameter + * keys should be prefixed by the module name. + * * @param array $context * (optional) Array with contextual data to be used for the configuration * factory. Defaults to an empty array. diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index a52e1af..a6458ac 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -1072,7 +1072,7 @@ function locale_config_factory(ConfigFactory $factory) { if (!$factory->getContext('locale.language')) { // Add user's language for user context. if ($account = $factory->getContext('user.account')) { - $factory->setContext('locale.language', user_preferred_language($account)); + $factory->setContext('locale.language', language_load(user_preferred_langcode($account))); } } } diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc index 396f4c0..76f697f 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -270,8 +270,8 @@ function user_admin_account_validate($form, &$form_state) { * @see user_admin_settings_submit() */ function user_admin_settings($form, &$form_state) { - $config = config('user.settings'); - $mail_config = config('user.mail'); + $config = config_admin('user.settings'); + $mail_config = config_admin('user.mail'); // Settings for anonymous users. $form['anonymous_settings'] = array( diff --git a/core/modules/user/user.module b/core/modules/user/user.module index b7ac23d..6614bdc 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -2083,35 +2083,21 @@ function user_view_multiple($accounts, $view_mode = 'full', $langcode = NULL) { function user_mail($key, &$message, $params) { $langcode = $message['langcode']; $variables = array('user' => $params['account']); - $message['subject'] .= _user_mail_text($key . '.subject', $langcode, $variables); - $message['body'][] = _user_mail_text($key . '.body', $langcode, $variables); -} - -/** - * Returns a mail string for a variable name. - * - * @param string $key - * The config key that provides the mail text. - * @param string $langcode - * (optional) A language code to use to generate the e-mail text. - * @param array $variables - * (optional) An array of token keys and values. - * - * @return - * A string value containing the text for the user.mail config key. - */ -function _user_mail_text($key, $langcode = NULL, $variables = array()) { + // Get a configuration object customized for this user, that may be localized + // for the user's language. + $mail_config = config_factory(array('user.account' => $params['account']))->get('user.mail')->load(); // We do not sanitize the token replacement, since the output of this // replacement is intended for an e-mail message, not a web browser. - return token_replace(config('user.mail')->get($key), $variables, array('langcode' => $langcode, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); + $token_options = array('langcode' => $langcode, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE); + $message['subject'] .= token_replace($mail_config->get($key . '.subject'), $variables, $token_options); + $message['body'][] = token_replace($mail_config->get($key . '.body'), $variables, $token_options); } /** * Token callback to add unsafe tokens for user mails. * - * This function is used by the token_replace() call at the end of - * _user_mail_text() to set up some additional tokens that can be - * used in email messages generated by user_mail(). + * This function is used by the token_replace() to set up some additional + * tokens that can be used in email messages generated by user_mail(). * * @param $replacements * An associative array variable containing mappings from token names to