diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 846146a..b68b9b8 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -4,6 +4,7 @@ use Drupal\Core\Database\Database; use Symfony\Component\ClassLoader\UniversalClassLoader; use Symfony\Component\ClassLoader\ApcUniversalClassLoader; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Language\Language; /** * @file @@ -207,11 +208,6 @@ const LANGUAGE_NOT_APPLICABLE = 'zxx'; const LANGUAGE_MULTIPLE = 'mul'; /** - * The type of language used to define the content language. - */ -const LANGUAGE_TYPE_CONTENT = 'language_content'; - -/** * The type of language used to select the user interface. */ const LANGUAGE_TYPE_INTERFACE = 'language_interface'; @@ -2532,7 +2528,6 @@ function drupal_language_initialize() { // 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); } @@ -2554,7 +2549,7 @@ function language_types_get_all() { function language_types_get_default() { return array( LANGUAGE_TYPE_INTERFACE => TRUE, - LANGUAGE_TYPE_CONTENT => FALSE, + Language::CONTENT => FALSE, LANGUAGE_TYPE_URL => FALSE, ); } diff --git a/core/includes/common.inc b/core/includes/common.inc index f3cdd69..bea4f84 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1,6 +1,7 @@ get(LANGUAGE_TYPE_CONTENT)->langcode; + $langcode = $langcode ? $langcode : drupal_container()->get(Language::CONTENT)->langcode; $output = "\n"; $output .= ' ' . check_plain($title) . "\n"; diff --git a/core/includes/language.inc b/core/includes/language.inc index 8e5f1ac..f183617 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -5,6 +5,8 @@ * Multiple language handling functionality. */ +use Drupal\Core\Language\Language; + /** * No language negotiation. The default language is used. */ @@ -420,7 +422,7 @@ function language_url_split_prefix($path, $languages) { * @return * An array of language codes. */ -function language_fallback_get_candidates($type = LANGUAGE_TYPE_CONTENT) { +function language_fallback_get_candidates($type = Language::CONTENT) { $fallback_candidates = &drupal_static(__FUNCTION__); if (!isset($fallback_candidates)) { diff --git a/core/lib/Drupal/Core/Language/Language.php b/core/lib/Drupal/Core/Language/Language.php index 9b9223d..c546712 100644 --- a/core/lib/Drupal/Core/Language/Language.php +++ b/core/lib/Drupal/Core/Language/Language.php @@ -17,6 +17,12 @@ namespace Drupal\Core\Language; * @see language_default() */ class Language { + + /** + * The type of language used to define the content language. + */ + const CONTENT = 'language_content'; + // Properties within the Language are set up as the default language. public $name = 'English'; public $langcode = 'en'; diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index e70b136..c52bb16 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -10,6 +10,7 @@ */ use Drupal\node\Node; +use Drupal\Core\Language\Language; /** * Comment is awaiting approval. @@ -951,7 +952,7 @@ function comment_prepare_thread(&$comments) { */ function comment_view(Comment $comment, Node $node, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = $GLOBALS['language_content']->langcode; + $langcode = drupal_container()->get(Language::CONTENT)->langcode; } // Populate $comment->content with a render() array. @@ -1018,7 +1019,7 @@ function comment_view(Comment $comment, Node $node, $view_mode = 'full', $langco */ function comment_build_content(Comment $comment, Node $node, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = $GLOBALS['language_content']->langcode; + $langcode = drupal_container()->get(Language::CONTENT)->langcode; } // Remove previously built content, if exists. @@ -1675,7 +1676,8 @@ function comment_forms() { * @ingroup forms */ function comment_form($form, &$form_state, Comment $comment) { - global $user, $language_content; + global $user; + $language_content = drupal_container()->get(Language::CONTENT); // During initial form build, add the comment entity to the form state for // use during form building and processing. During a rebuild, use what is in diff --git a/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc index f054bf1..5052928 100644 --- a/core/modules/field/field.multilingual.inc +++ b/core/modules/field/field.multilingual.inc @@ -5,6 +5,8 @@ * Functions implementing Field API multilingual support. */ +use Drupal\Core\Language\Language; + /** * @defgroup field_language Field Language API * @{ @@ -247,7 +249,7 @@ function field_valid_language($langcode, $default = TRUE) { if (in_array($langcode, $enabled_languages)) { return $langcode; } - global $language_content; + $language_content = drupal_container()->get(Language::CONTENT); return $default ? language_default()->langcode : $language_content->langcode; } diff --git a/core/modules/language/language.module b/core/modules/language/language.module index c7d6f18..93f9de2 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -5,6 +5,8 @@ * Add language handling functionality to Drupal. */ +use Drupal\Core\Language\Language; + /** * Implements hook_help(). */ @@ -276,7 +278,7 @@ function language_language_types_info() { 'name' => t('User interface text'), 'description' => t('Order of language detection methods for user interface text. If a translation of user interface text is available in the detected language, it will be displayed.'), ), - LANGUAGE_TYPE_CONTENT => array( + Language::CONTENT => array( 'name' => t('Content'), 'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'), 'fixed' => array(LANGUAGE_NEGOTIATION_INTERFACE), @@ -296,7 +298,7 @@ function language_language_negotiation_info() { $negotiation_info = array(); $negotiation_info[LANGUAGE_NEGOTIATION_URL] = array( - 'types' => array(LANGUAGE_TYPE_CONTENT, LANGUAGE_TYPE_INTERFACE, LANGUAGE_TYPE_URL), + 'types' => array(Language::CONTENT, LANGUAGE_TYPE_INTERFACE, LANGUAGE_TYPE_URL), 'callbacks' => array( 'negotiation' => 'language_from_url', 'language_switch' => 'language_switcher_url', @@ -340,7 +342,7 @@ function language_language_negotiation_info() { ); $negotiation_info[LANGUAGE_NEGOTIATION_INTERFACE] = array( - 'types' => array(LANGUAGE_TYPE_CONTENT), + 'types' => array(Language::CONTENT), 'callbacks' => array('negotiation' => 'language_from_interface'), 'file' => $file, 'weight' => 8, diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index d740c67..c03bfe6 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -5,6 +5,8 @@ * Install, update and uninstall functions for the locale module. */ +use Drupal\Core\Language\Language; + /** * Implements hook_uninstall(). */ @@ -448,7 +450,7 @@ function locale_update_8007() { // is not available its functionality is rebuild. $language_types = variable_get('language_types', array( LANGUAGE_TYPE_INTERFACE => TRUE, - LANGUAGE_TYPE_CONTENT => FALSE, + Language::CONTENT => FALSE, LANGUAGE_TYPE_URL => FALSE, )); foreach ($language_types as $language_type => $configurable) { diff --git a/core/modules/locale/locale.test b/core/modules/locale/locale.test index ded11ef..1d2476e 100644 --- a/core/modules/locale/locale.test +++ b/core/modules/locale/locale.test @@ -20,6 +20,7 @@ * - a functional test fot language types/negotiation info. */ +use Drupal\Core\Language\Language; /** * Functional tests for language configuration's effect on negotiation setup. @@ -1614,7 +1615,7 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase { drupal_load('module', 'locale'); variable_set('language_types', language_types_get_default() + array('language_custom' => TRUE)); variable_set('language_negotiation_' . LANGUAGE_TYPE_INTERFACE, language_language_negotiation_info()); - variable_set('language_negotiation_' . LANGUAGE_TYPE_CONTENT, language_language_negotiation_info()); + variable_set('language_negotiation_' . Language::CONTENT, language_language_negotiation_info()); variable_set('language_negotiation_' . LANGUAGE_TYPE_URL, language_language_negotiation_info()); // Change language negotiation settings. @@ -1644,7 +1645,7 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase { $this->assertTrue(count(language_types_get_all()) == count(language_types_get_default()), t('Language types reset')); $language_negotiation = language_negotiation_method_get_first(LANGUAGE_TYPE_INTERFACE) == LANGUAGE_NEGOTIATION_DEFAULT; $this->assertTrue($language_negotiation, t('Interface language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set')))); - $language_negotiation = language_negotiation_method_get_first(LANGUAGE_TYPE_CONTENT) == LANGUAGE_NEGOTIATION_DEFAULT; + $language_negotiation = language_negotiation_method_get_first(Language::CONTENT) == LANGUAGE_NEGOTIATION_DEFAULT; $this->assertTrue($language_negotiation, t('Content language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set')))); $language_negotiation = language_negotiation_method_get_first(LANGUAGE_TYPE_URL) == LANGUAGE_NEGOTIATION_DEFAULT; $this->assertTrue($language_negotiation, t('URL language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set')))); @@ -2872,7 +2873,7 @@ class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase { $this->assertTrue($assert, t('Field language correctly changed.')); // Enable content language URL detection. - language_negotiation_set(LANGUAGE_TYPE_CONTENT, array(LANGUAGE_NEGOTIATION_URL => 0)); + language_negotiation_set(Language::CONTENT, array(LANGUAGE_NEGOTIATION_URL => 0)); // Test multilingual field language fallback logic. $this->drupalGet("it/node/$node->nid"); @@ -3119,7 +3120,7 @@ class LocaleLanguageNegotiationInfoFunctionalTest extends DrupalWebTestCase { // negotiation settings with the proper flag enabled. variable_set('locale_test_content_language_type', TRUE); $this->languageNegotiationUpdate(); - $type = LANGUAGE_TYPE_CONTENT; + $type = Language::CONTENT; $language_types = variable_get('language_types', language_types_get_default()); $this->assertTrue($language_types[$type], t('Content language type is configurable.')); @@ -3161,7 +3162,7 @@ class LocaleLanguageNegotiationInfoFunctionalTest extends DrupalWebTestCase { $last = variable_get('locale_test_language_negotiation_last', array()); foreach (language_types_get_all() as $type) { $langcode = $last[$type]; - $value = $type == LANGUAGE_TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en'; + $value = $type == Language::CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en'; $this->assertEqual($langcode, $value, t('The negotiated language for %type is %language', array('%type' => $type, '%language' => $langcode))); } diff --git a/core/modules/locale/tests/locale_test.module b/core/modules/locale/tests/locale_test.module index 93dfaa1..2aaa320 100644 --- a/core/modules/locale/tests/locale_test.module +++ b/core/modules/locale/tests/locale_test.module @@ -5,6 +5,8 @@ * Mock module for locale layer tests. */ +use Drupal\Core\Language\Language; + /** * Implements hook_boot(). * @@ -49,7 +51,7 @@ function locale_test_language_types_info() { */ function locale_test_language_types_info_alter(array &$language_types) { if (variable_get('locale_test_content_language_type', FALSE)) { - unset($language_types[LANGUAGE_TYPE_CONTENT]['fixed']); + unset($language_types[Language::CONTENT]['fixed']); } } @@ -70,7 +72,7 @@ function locale_test_language_negotiation_info() { return array( 'test_language_negotiation_method' => array( 'name' => t('Test'), - 'types' => array(LANGUAGE_TYPE_CONTENT, 'test_language_type', 'fixed_test_language_type'), + 'types' => array(Language::CONTENT, 'test_language_type', 'fixed_test_language_type'), ) + $info, 'test_language_negotiation_method_ts' => array( 'name' => t('Type-specific test'), diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 9e21bfa..8a74c0e 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -4,6 +4,7 @@ use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Database\Query\SelectExtender; use Drupal\Core\Database\Query\SelectInterface; use Drupal\node\Node; +use Drupal\Core\Language\Language; /** * @file @@ -1149,7 +1150,7 @@ function node_revision_delete($revision_id) { */ function node_view(Node $node, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = $GLOBALS['language_content']->langcode; + $langcode = drupal_container()->get(Language::CONTENT)->langcode; } // Populate $node->content with a render() array. @@ -1211,7 +1212,7 @@ function node_view(Node $node, $view_mode = 'full', $langcode = NULL) { */ function node_build_content(Node $node, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = $GLOBALS['language_content']->langcode; + $langcode = drupal_container()->get(Language::CONTENT)->langcode; } // Remove previously built content, if exists. @@ -2397,7 +2398,8 @@ function node_block_list_alter(&$blocks) { * @see node_menu() */ function node_feed($nids = FALSE, $channel = array()) { - global $base_url, $language_content; + global $base_url; + $language_content = drupal_container()->get(Language::CONTENT); if ($nids === FALSE) { $nids = db_select('node', 'n') diff --git a/core/modules/system/language.api.php b/core/modules/system/language.api.php index 9f28619..b9334f4 100644 --- a/core/modules/system/language.api.php +++ b/core/modules/system/language.api.php @@ -50,11 +50,13 @@ function hook_language_init() { * The language type the links will switch. * @param $path * The current path. + * + * @see Drupal\Core\Language\Language */ function hook_language_switch_links_alter(array &$links, $type, $path) { global $language_interface; - if ($type == LANGUAGE_TYPE_CONTENT && isset($links[$language_interface->langcode])) { + if ($type == Language::CONTENT && isset($links[$language_interface->langcode])) { foreach ($links[$language_interface->langcode] as $link) { $link['attributes']['class'][] = 'active-language'; } diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 024f3ed..2c8dec6 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -6,6 +6,7 @@ */ use Drupal\node\Node; +use Drupal\Core\Language\Language; /** * Denotes that no term in the vocabulary has a parent. @@ -582,7 +583,7 @@ function taxonomy_term_delete_multiple(array $tids) { */ function taxonomy_term_view(TaxonomyTerm $term, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = $GLOBALS['language_content']->langcode; + $langcode = drupal_container()->get(Language::CONTENT)->langcode; } field_attach_prepare_view('taxonomy_term', array($term->tid => $term), $view_mode, $langcode); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 4219728..bfeaadc 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1,6 +1,7 @@ langcode; + $langcode = drupal_container()->get(Language::CONTENT)->langcode; } // Retrieve all profile fields and attach to $account->content. @@ -2395,7 +2396,7 @@ function user_view($account, $view_mode = 'full', $langcode = NULL) { */ function user_build_content($account, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = $GLOBALS['language_content']->langcode; + $langcode = drupal_container()->get(Language::CONTENT)->langcode; } // Remove previously built content, if exists.