diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 3af9f02..9e1cabc 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1353,12 +1353,11 @@ function drupal_unpack($obj, $field = 'data') { * @ingroup sanitization */ function t($string, array $args = array(), array $options = array()) { - $language_interface = drupal_container()->get(LANGUAGE_TYPE_INTERFACE); static $custom_strings; // Merge in default. if (empty($options['langcode'])) { - $options['langcode'] = isset($language_interface->langcode) ? $language_interface->langcode : LANGUAGE_SYSTEM; + $options['langcode'] = drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode; } if (empty($options['context'])) { $options['context'] = ''; @@ -2309,8 +2308,10 @@ function drupal_get_bootstrap_phase() { * * Example: * @code - * // Register the LANGUAGE_TYPE_INTERFACE definition. Registered definitions + * // Register the LANGUAGE_TYPE_INTERFACE definition. Registered definitions * // do not necessarily need to be named by a constant. + * // See http://symfony.com/doc/current/components/dependency_injection.html + * // for usage examples of adding object initialization code after register(). * $container = drupal_container(); * $container->register(LANGUAGE_TYPE_INTERFACE, 'Drupal\\Core\\Language\\Language'); * @@ -2485,34 +2486,12 @@ function drupal_language_initialize() { $types = language_types_get_all(); $container = drupal_container(); - // Ensure the language is correctly returned, even without multilanguage - // support. Also make sure we have a $language fallback, in case a language - // negotiation callback needs to do a full bootstrap. - // Useful for eg. XML/HTML 'lang' attributes. - // $language_interface: http://drupal.org/node/1510686 - // $language_url: http://drupal.org/node/1512310 - // $language_content: http://drupal.org/node/1512308 - // @todo Eliminate this line once all language globals are eliminated. - $default = language_default(); - foreach ($types as $type) { - $GLOBALS[$type] = $default; - - // Register the language types to the Drupal Container as the default - // language. When the types are retrieved, these Language objects will be - // dynamically constructed, with their default property set to TRUE. - $container->register($type, 'Drupal\\Core\\Language\\Language') - ->addMethodCall('extend', array($default)); - } + // Ensure a language object is registered for each language type, whether the + // site is multilingual or not. if (language_multilingual()) { include_once DRUPAL_ROOT . '/core/includes/language.inc'; foreach ($types as $type) { $language = language_types_initialize($type); - $GLOBALS[$type] = $language; - - // Swap the previously registered language type with the newly initialized - // one. This time, however, instead of setting it as the default, we will - // be setting it to what was given to use from when we called the - // language_types_initialize() function. $container->register($type, 'Drupal\\Core\\Language\\Language') ->addMethodCall('extend', array($language)); } @@ -2520,6 +2499,22 @@ function drupal_language_initialize() { // environments. bootstrap_invoke_all('language_init'); } + else { + $default = language_default(); + foreach ($types as $type) { + $container->register($type, 'Drupal\\Core\\Language\\Language') + ->addMethodCall('extend', array($default)); + } + } + + // @todo Temporary backwards compatibility for code still using globals. + // Remove after these issues: + // - $language_interface: http://drupal.org/node/1510686 + // - $language_url: http://drupal.org/node/1512310 + // - $language_content: http://drupal.org/node/1512308 + foreach ($types as $type) { + $GLOBALS[$type] = $container->get($type); + } } /** diff --git a/core/includes/common.inc b/core/includes/common.inc index 50fc1ec..e57ca93 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1607,8 +1607,7 @@ function filter_xss_bad_protocol($string, $decode = TRUE) { * Arbitrary elements may be added using the $args associative array. */ function format_rss_channel($title, $link, $description, $items, $langcode = NULL, $args = array()) { - $language_content = drupal_container()->get(LANGUAGE_TYPE_CONTENT); - $langcode = $langcode ? $langcode : $language_content->langcode; + $langcode = $langcode ? $langcode : drupal_container()->get(LANGUAGE_TYPE_CONTENT)->langcode; $output = "\n"; $output .= ' ' . check_plain($title) . "\n"; @@ -1909,9 +1908,8 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL $timezones[$timezone] = timezone_open($timezone); } - $language_interface = drupal_container()->get(LANGUAGE_TYPE_INTERFACE); if (empty($langcode)) { - $langcode = isset($language_interface->langcode) ? $language_interface->langcode : LANGUAGE_SYSTEM; + $langcode = drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode; } switch ($type) { @@ -2351,7 +2349,6 @@ function drupal_attributes(array $attributes = array()) { * An HTML string containing a link to the given path. */ function l($text, $path, array $options = array()) { - $language_url = drupal_container()->get(LANGUAGE_TYPE_URL); static $use_theme = NULL; // Merge in defaults. @@ -2362,7 +2359,7 @@ function l($text, $path, array $options = array()) { // Append active class. if (($path == $_GET['q'] || ($path == '' && drupal_is_front_page())) && - (empty($options['language']) || $options['language']->langcode == $language_url->langcode)) { + (empty($options['language']) || $options['language']->langcode == drupal_container()->get(LANGUAGE_TYPE_URL)->langcode)) { $options['attributes']['class'][] = 'active'; } @@ -2518,8 +2515,7 @@ function drupal_deliver_html_page($page_callback_result) { drupal_add_http_header('X-UA-Compatible', 'IE=edge,chrome=1'); } - $language_interface = drupal_container()->get(LANGUAGE_TYPE_INTERFACE); - drupal_add_http_header('Content-Language', $language_interface->langcode); + drupal_add_http_header('Content-Language', drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode); // Menu status constants are integers; page content is a string or array. if (is_int($page_callback_result)) { diff --git a/core/includes/locale.inc b/core/includes/locale.inc index 3d0dd1b..a475396 100644 --- a/core/includes/locale.inc +++ b/core/includes/locale.inc @@ -112,8 +112,7 @@ const LANGUAGE_NEGOTIATION_URL_DOMAIN = 1; * The current interface language code. */ function locale_language_from_interface() { - $language_interface = drupal_container()->get(LANGUAGE_TYPE_INTERFACE); - return isset($language_interface->langcode) ? $language_interface->langcode : FALSE; + return drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode; } /** diff --git a/core/includes/path.inc b/core/includes/path.inc index 5545fc1..d6a0201 100644 --- a/core/includes/path.inc +++ b/core/includes/path.inc @@ -43,7 +43,6 @@ function drupal_path_initialize() { * found. */ function drupal_lookup_path($action, $path = '', $langcode = NULL) { - $language_url = drupal_container()->get(LANGUAGE_TYPE_URL); // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; if (!isset($drupal_static_fast)) { @@ -74,7 +73,7 @@ function drupal_lookup_path($action, $path = '', $langcode = NULL) { // language. If we used a language different from the one conveyed by the // requested URL, we might end up being unable to check if there is a path // alias matching the URL path. - $langcode = $langcode ? $langcode : $language_url->langcode; + $langcode = $langcode ? $langcode : drupal_container()->get(LANGUAGE_TYPE_URL)->langcode; if ($action == 'wipe') { $cache = array(); diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 7648bc8..1dbcadd 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2786,9 +2786,6 @@ function template_preprocess_maintenance_page(&$variables) { $language_interface = drupal_container()->get(LANGUAGE_TYPE_INTERFACE); - // set the default language if necessary - $language = isset($language_interface) ? $language_interface : language_default(); - $variables['head_title_array'] = $head_title; $variables['head_title'] = implode(' | ', $head_title); $variables['base_path'] = base_path(); @@ -2796,8 +2793,8 @@ function template_preprocess_maintenance_page(&$variables) { $variables['breadcrumb'] = ''; $variables['feed_icons'] = ''; $variables['help'] = ''; - $variables['language'] = $language; - $variables['language']->dir = $language->direction ? 'rtl' : 'ltr'; + $variables['language'] = $language_interface; + $variables['language']->dir = $language_interface->direction ? 'rtl' : 'ltr'; $variables['logo'] = theme_get_setting('logo'); $variables['messages'] = $variables['show_messages'] ? theme('status_messages') : ''; $variables['main_menu'] = array(); diff --git a/core/modules/system/language.api.php b/core/modules/system/language.api.php index aa8fd2f..9f28619 100644 --- a/core/modules/system/language.api.php +++ b/core/modules/system/language.api.php @@ -24,9 +24,9 @@ * did not happen yet and thus they cannot rely on translated variables. */ function hook_language_init() { - global $language_interface, $conf; + global $conf; - switch ($language_interface->langcode) { + switch (drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode) { case 'it': $conf['site_name'] = 'Il mio sito Drupal'; break;