diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index cf0e3dd..cdb913e 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2396,7 +2396,7 @@ function drupal_installation_attempted() { function drupal_language_initialize() { $language_manager = Drupal::languageManager(); $language_manager->init(); - Drupal::translation()->setDefaultLangcode($language_manager->getLanguage(Language::TYPE_INTERFACE)->langcode); + Drupal::translation()->setDefaultLangcode($language_manager->getLanguage(Language::TYPE_INTERFACE)->id); } /** @@ -2477,18 +2477,27 @@ function language_list($flags = Language::STATE_CONFIGURABLE) { $default = language_default(); if (language_multilingual() || module_exists('language')) { // Use language module configuration if available. - $languages = db_query('SELECT * FROM {language} ORDER BY weight ASC, name ASC')->fetchAllAssoc('langcode', PDO::FETCH_ASSOC); + $language_entities = config_get_storage_names_with_prefix('language.entity'); // Initialize default property so callers have an easy reference and can // save the same object without data loss. - foreach ($languages as $langcode => $info) { - $info['default'] = ($langcode == $default->langcode); - $languages[$langcode] = new Language($info); + foreach ($language_entities as $langcode_config_name) { + $langcode = substr($langcode_config_name, strlen('language.entity.')); + $info = config($langcode_config_name)->get(); + $languages[$langcode] = new Language(array( + 'default' => ($info['id'] == $default->id), + 'name' => $info['label'], + 'id' => $info['id'], + 'direction' => $info['direction'], + 'locked' => $info['locked'], + 'weight' => $info['weight'], + )); } + Language::sort($languages); } else { // No language module, so use the default language only. - $languages = array($default->langcode => $default); + $languages = array($default->id => $default); // Add the special languages, they will be filtered later if needed. $languages += language_default_locked_languages($default->weight); } @@ -2536,12 +2545,12 @@ function language_default_locked_languages($weight = 0) { $languages = array(); $languages[Language::LANGCODE_NOT_SPECIFIED] = new Language(array( - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, + 'id' => Language::LANGCODE_NOT_SPECIFIED, 'name' => t('Not specified'), 'weight' => ++$weight, ) + $locked_language); $languages[Language::LANGCODE_NOT_APPLICABLE] = new Language(array( - 'langcode' => Language::LANGCODE_NOT_APPLICABLE, + 'id' => Language::LANGCODE_NOT_APPLICABLE, 'name' => t('Not applicable'), 'weight' => ++$weight, ) + $locked_language); @@ -2606,8 +2615,8 @@ function language_is_locked($langcode) { * A language object. */ function language_default() { - $info = variable_get('language_default', array( - 'langcode' => 'en', + $info = (array) variable_get('language_default', array( + 'id' => 'en', 'name' => 'English', 'direction' => 0, 'weight' => 0, diff --git a/core/includes/common.inc b/core/includes/common.inc index 3ff8096..92db595 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -904,7 +904,7 @@ function filter_xss_bad_protocol($string) { * Arbitrary elements may be added using the $args associative array. */ function format_rss_channel($title, $link, $description, $items, $langcode = NULL, $args = array()) { - $langcode = $langcode ? $langcode : language(Language::TYPE_CONTENT)->langcode; + $langcode = $langcode ? $langcode : language(Language::TYPE_CONTENT)->id; $output = "\n"; $output .= ' ' . check_plain($title) . "\n"; @@ -1417,7 +1417,7 @@ function l($text, $path, array $options = array()) { $active = array( 'path' => current_path(), 'front_page' => drupal_is_front_page(), - 'language' => language(Language::TYPE_URL)->langcode, + 'language' => language(Language::TYPE_URL)->id, 'query' => Drupal::service('request')->query->all(), ); } @@ -1428,7 +1428,7 @@ function l($text, $path, array $options = array()) { // An active link's path is equal to the current path. $variables['url_is_active'] = ($path == $active['path'] || ($path == '' && $active['front_page'])) // The language of an active link is equal to the current language. - && (empty($variables['options']['language']) || $variables['options']['language']->langcode == $active['language']) + && (empty($variables['options']['language']) || $variables['options']['language']->id == $active['language']) // The query parameters of an active link are equal to the current parameters. && ($variables['options']['query'] == $active['query']); @@ -5041,7 +5041,7 @@ function drupal_render_cid_parts($granularity = NULL) { // part. if (language_multilingual()) { foreach (language_types_get_configurable() as $language_type) { - $cid_parts[] = language($language_type)->langcode; + $cid_parts[] = language($language_type)->id; } } diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 9994406..ffe879a 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -60,7 +60,7 @@ function entity_info_cache_clear() { function entity_get_bundles($entity_type = NULL) { $bundles = &drupal_static(__FUNCTION__); if (!$bundles) { - $langcode = language(Language::TYPE_INTERFACE)->langcode; + $langcode = language(Language::TYPE_INTERFACE)->id; if ($cache = cache()->get("entity_bundle_info:$langcode")) { $bundles = $cache->data; } @@ -118,7 +118,7 @@ function entity_invoke_bundle_hook($hook, $entity_type, $bundle, $bundle_new = N function entity_get_form_modes($entity_type = NULL) { $form_modes = &drupal_static(__FUNCTION__); if (!$form_modes) { - $langcode = language(Language::TYPE_INTERFACE)->langcode; + $langcode = language(Language::TYPE_INTERFACE)->id; if ($cache = cache()->get("entity_form_mode_info:$langcode")) { $form_modes = $cache->data; } @@ -156,7 +156,7 @@ function entity_get_form_modes($entity_type = NULL) { function entity_get_view_modes($entity_type = NULL) { $view_modes = &drupal_static(__FUNCTION__); if (!$view_modes) { - $langcode = language(Language::TYPE_INTERFACE)->langcode; + $langcode = language(Language::TYPE_INTERFACE)->id; if ($cache = cache()->get("entity_view_mode_info:$langcode")) { $view_modes = $cache->data; } diff --git a/core/includes/form.inc b/core/includes/form.inc index 4689711..abad44e 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -3854,7 +3854,7 @@ function form_process_machine_name($element, &$form_state) { 'machineName' => array( '#' . $source['#id'] => $element['#machine_name'], ), - 'langcode' => $language->langcode, + 'langcode' => $language->id, ), ); $element['#attached']['library'][] = array('system', 'drupal.machine-name'); diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 77771d8..086da27 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -298,7 +298,7 @@ function install_begin_request(&$install_state) { // (eg. pre-database data screens we are unable to persistently store // the default language), we should set language_default so the proper // language is used to display installer pages as early as possible. - if (!empty($install_state['parameters']['langcode']) && language_default()->langcode != $install_state['parameters']['langcode']) { + if (!empty($install_state['parameters']['langcode']) && language_default()->id != $install_state['parameters']['langcode']) { $GLOBALS['conf']['language_default'] = array('langcode' => $install_state['parameters']['langcode']); } @@ -1547,7 +1547,7 @@ function install_select_language_form($form, &$form_state, $files = array()) { foreach ($files as $langcode => $uri) { $select_options[$langcode] = isset($standard_languages[$langcode]) ? $standard_languages[$langcode][1] : $langcode; $browser_options[$langcode] = new Language(array( - 'langcode' => $langcode, + 'id' => $langcode, )); } } @@ -1556,7 +1556,7 @@ function install_select_language_form($form, &$form_state, $files = array()) { foreach ($standard_languages as $langcode => $language_names) { $select_options[$langcode] = $language_names[1]; $browser_options[$langcode] = new Language(array( - 'langcode' => $langcode, + 'id' => $langcode, )); } } @@ -1819,7 +1819,7 @@ function install_import_translations(&$install_state) { // Drupal does not know about this language, so we prefill its values with // our best guess. The user will be able to edit afterwards. $language = new Language(array( - 'langcode' => $langcode, + 'id' => $langcode, 'name' => $langcode, 'default' => TRUE, )); @@ -1828,7 +1828,7 @@ function install_import_translations(&$install_state) { else { // A known predefined language, details will be filled in properly. $language = new Language(array( - 'langcode' => $langcode, + 'id' => $langcode, 'default' => TRUE, )); language_save($language); @@ -2497,7 +2497,7 @@ function install_configure_form_submit($form, &$form_state) { config('system.site') ->set('name', $form_state['values']['site_name']) ->set('mail', $form_state['values']['site_mail']) - ->set('langcode', language_default()->langcode) + ->set('langcode', language_default()->id) ->save(); config('system.timezone') diff --git a/core/includes/language.inc b/core/includes/language.inc index 896cf69..976dd75 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -92,7 +92,7 @@ * * // If we are on an administrative path, override with the default language. * if (isset($_GET['q']) && strtok($_GET['q'], '/') == 'admin') { - * return language_default()->langcode; + * return language_default()->id; * } * return $langcode; * } @@ -409,7 +409,7 @@ function language_negotiation_info() { $languages = language_list(); $selected_language = $languages[language_from_selected($languages)]; $description = 'Language based on a selected language. '; - $description .= ($selected_language->langcode == language_default()->langcode) ? "(Site's default language (@language_name))" : '(@language_name)'; + $description .= ($selected_language->id == language_default()->id) ? "(Site's default language (@language_name))" : '(@language_name)'; // Add the default language negotiation method. $negotiation_info[LANGUAGE_NEGOTIATION_SELECTED] = array( 'callbacks' => array( @@ -488,9 +488,9 @@ function language_from_selected($languages) { $langcode = (string) config('language.negotiation')->get('selected_langcode'); // Replace the site's default langcode by its real value. if ($langcode == 'site_default') { - $langcode = language_default()->langcode; + $langcode = language_default()->id; } - return isset($languages[$langcode]) ? $langcode : language_default()->langcode; + return isset($languages[$langcode]) ? $langcode : language_default()->id; } /** @@ -517,7 +517,7 @@ function language_url_split_prefix($path, $languages) { // Search prefix within enabled languages. $prefixes = language_negotiation_url_prefixes(); foreach ($languages as $language) { - if (isset($prefixes[$language->langcode]) && $prefixes[$language->langcode] == $prefix) { + if (isset($prefixes[$language->id]) && $prefixes[$language->id] == $prefix) { // Rebuild $path with the language removed. return array($language, implode('/', $args)); } diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 66d1e2a..2cb0e80 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -1161,7 +1161,7 @@ function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) { // Use $mlid as a flag for whether the data being loaded is for the whole tree. $mlid = isset($link['mlid']) ? $link['mlid'] : 0; // Generate a cache ID (cid) specific for this $menu_name, $link, $language, and depth. - $cid = 'links:' . $menu_name . ':all:' . $mlid . ':' . $language_interface->langcode . ':' . (int) $max_depth; + $cid = 'links:' . $menu_name . ':all:' . $mlid . ':' . $language_interface->id . ':' . (int) $max_depth; if (!isset($tree[$cid])) { // If the static variable doesn't have the data, check {cache_menu}. @@ -1277,7 +1277,7 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail = $max_depth = min($max_depth, MENU_MAX_DEPTH); } // Generate a cache ID (cid) specific for this page. - $cid = 'links:' . $menu_name . ':page:' . $item['href'] . ':' . $language_interface->langcode . ':' . (int) $item['access'] . ':' . (int) $max_depth; + $cid = 'links:' . $menu_name . ':page:' . $item['href'] . ':' . $language_interface->id . ':' . (int) $item['access'] . ':' . (int) $max_depth; // If we are asked for the active trail only, and $menu_name has not been // built and cached for this page yet, then this likely means that it // won't be built anymore, as this function is invoked from @@ -1425,7 +1425,7 @@ function _menu_build_tree($menu_name, array $parameters = array()) { if (isset($parameters['expanded'])) { sort($parameters['expanded']); } - $tree_cid = 'links:' . $menu_name . ':tree-data:' . $language_interface->langcode . ':' . hash('sha256', serialize($parameters)); + $tree_cid = 'links:' . $menu_name . ':tree-data:' . $language_interface->id . ':' . hash('sha256', serialize($parameters)); // If we do not have this tree in the static cache, check {cache_menu}. if (!isset($trees[$tree_cid])) { diff --git a/core/includes/theme.inc b/core/includes/theme.inc index a44254e..9dac5ae 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1731,7 +1731,7 @@ function theme_links($variables) { // Handle links. if (isset($link['href'])) { $is_current_path = ($link['href'] == current_path() || ($link['href'] == '' && drupal_is_front_page())); - $is_current_language = (empty($link['language']) || $link['language']->langcode == $language_url->langcode); + $is_current_language = (empty($link['language']) || $link['language']->id == $language_url->id); if ($is_current_path && $is_current_language) { $class[] = 'active'; } @@ -2590,7 +2590,7 @@ function template_preprocess_html(&$variables) { $variables['html_attributes'] = new Attribute; // HTML element attributes. - $variables['html_attributes']['lang'] = $language_interface->langcode; + $variables['html_attributes']['lang'] = $language_interface->id; $variables['html_attributes']['dir'] = $language_interface->direction ? 'rtl' : 'ltr'; // Add favicon. diff --git a/core/includes/update.inc b/core/includes/update.inc index 3659caf..91715f3 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -320,9 +320,9 @@ function update_prepare_d8_bootstrap() { // triggers a call into system_stream_wrappers(), which calls t(), which // calls into language_default(). $language_default = variable_get('language_default'); - if (!empty($language_default) && (isset($language_default->langcode) || isset($language_default->language))) { - if (!isset($language_default->langcode)) { - $language_default->langcode = $language_default->language; + if (!empty($language_default) && (isset($language_default->id) || isset($language_default->language))) { + if (!isset($language_default->id)) { + $language_default->id = $language_default->language; } unset($language_default->language); // In D8, the 'language_default' is not anymore an object, but an array, @@ -535,7 +535,7 @@ function update_prepare_d8_language() { foreach ($languages as $language) { db_insert('language') ->fields(array( - 'langcode' => $language->langcode, + 'langcode' => $language->id, 'name' => $language->name, 'weight' => $language->weight, // These languages are locked, default to enabled. @@ -549,7 +549,7 @@ function update_prepare_d8_language() { $language_default = variable_get('language_default'); if (!empty($language_default)) { if (isset($language_default->language)) { - $language_default->langcode = $language_default->language; + $language_default->id = $language_default->language; unset($language_default->language); } unset($language_default->enabled); @@ -559,6 +559,21 @@ function update_prepare_d8_language() { variable_set('language_default', (array) $language_default); } + // Convert languages to config entities. + $result = db_query('SELECT * FROM {language}'); + $uuid = new Uuid(); + foreach ($result as $language) { + config('language.entity.' . $language->langcode) + ->set('id', $language->langcode) + ->set('uuid', $uuid->generate()) + ->set('label', $language->name) + ->set('direction', $language->direction) + ->set('weight', $language->weight) + ->set('locked', $language->locked) + ->set('langcode', 'en') + ->save(); + } + // Add column to track customized string status to locales_target. // When updating in a non-English language, the locale translation system is // triggered, which attempts to query string translations already. @@ -1573,3 +1588,78 @@ function update_replace_permissions($replace) { ->save(); } } + +/** + * Returns a list of languages set up on the site during upgrades. + * + * @param $flags + * (optional) Specifies the state of the languages that have to be returned. + * It can be: Language::STATE_CONFIGURABLE, Language::STATE_LOCKED, + * Language::STATE_ALL. + * + * @return array + * An associative array of languages, keyed by the language code, ordered by + * weight ascending and name ascending. + */ +function update_language_list($flags = Language::STATE_CONFIGURABLE) { + + $languages = &drupal_static(__FUNCTION__); + + // Initialize master language list. + if (!isset($languages)) { + // Initialize local language list cache. + $languages = array(); + + // Fill in master language list based on current configuration. + $default = language_default(); + if (language_multilingual() || module_exists('language')) { + // Use language module configuration if available. We can not use + // entity_load_multiple() because this breaks during updates. + $language_entities = config_get_storage_names_with_prefix('language.entity'); + + // Initialize default property so callers have an easy reference and can + // save the same object without data loss. + foreach ($language_entities as $langcode_config_name) { + $langcode = substr($langcode_config_name, strlen('language.entity.')); + $info = config($langcode_config_name)->get(); + $languages[$langcode] = new Language(array( + 'default' => ($info['id'] == $default->id), + 'name' => $info['label'], + 'id' => $info['id'], + 'direction' => $info['direction'], + 'locked' => $info['locked'], + 'weight' => $info['weight'], + )); + } + Language::sort($languages); + } + else { + // No language module, so use the default language only. + $languages = array($default->id => $default); + // Add the special languages, they will be filtered later if needed. + $languages += language_default_locked_languages($default->weight); + } + } + + // Filter the full list of languages based on the value of the $all flag. By + // default we remove the locked languages, but the caller may request for + // those languages to be added as well. + $filtered_languages = array(); + + // Add the site's default language if flagged as allowed value. + if ($flags & Language::STATE_SITE_DEFAULT) { + $default = isset($default) ? $default : language_default(); + // Rename the default language. + $default->name = t("Site's default language (@lang_name)", array('@lang_name' => $default->name)); + $filtered_languages['site_default'] = $default; + } + + foreach ($languages as $langcode => $language) { + if (($language->locked && !($flags & Language::STATE_LOCKED)) || (!$language->locked && !($flags & Language::STATE_CONFIGURABLE))) { + continue; + } + $filtered_languages[$langcode] = $language; + } + + return $filtered_languages; +} diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index b86e1f0..5290ec6 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -309,7 +309,7 @@ public function create(array $values) { $class::preCreate($this, $values); // Set default language to site default if not provided. - $values += array('langcode' => language_default()->langcode); + $values += array('langcode' => language_default()->id); $entity = new $class($values, $this->entityType); // Mark this entity as new, so isNew() returns TRUE. This does not check diff --git a/core/lib/Drupal/Core/Datetime/Date.php b/core/lib/Drupal/Core/Datetime/Date.php index 93fd00f..45aa3be 100644 --- a/core/lib/Drupal/Core/Datetime/Date.php +++ b/core/lib/Drupal/Core/Datetime/Date.php @@ -93,7 +93,7 @@ public function format($timestamp, $type = 'medium', $format = '', $timezone = N } if (empty($langcode)) { - $langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->langcode; + $langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id; } // Create a DrupalDateTime object from the timestamp and timezone. diff --git a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php index 0179bcc..0a283ac 100644 --- a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php +++ b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php @@ -60,7 +60,7 @@ class DrupalDateTime extends DateTimePlus { public function __construct($time = 'now', $timezone = NULL, $format = NULL, $settings = array()) { // We can set the langcode and country using Drupal values. - $settings['langcode'] = !empty($settings['langcode']) ? $settings['langcode'] : language(Language::TYPE_INTERFACE)->langcode; + $settings['langcode'] = !empty($settings['langcode']) ? $settings['langcode'] : language(Language::TYPE_INTERFACE)->id; $settings['country'] = !empty($settings['country']) ? $settings['country'] : config('system.date')->get('country.default'); // Instantiate the parent class. diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php index fe11758..2f20916 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php @@ -412,7 +412,7 @@ public function save(EntityInterface $entity) { */ protected function saveRevision(EntityInterface $entity) { $return = $entity->id(); - $default_langcode = $entity->language()->langcode; + $default_langcode = $entity->language()->id; if (!$entity->isNewRevision()) { // Delete to handle removed values. @@ -534,7 +534,7 @@ protected function mapToRevisionStorageRecord(ComplexDataInterface $entity) { * The record to store. */ protected function mapToDataStorageRecord(EntityInterface $entity, $langcode) { - $default_langcode = $entity->language()->langcode; + $default_langcode = $entity->language()->id; // Don't use strict mode, this way there's no need to do checks here, as // non-translatable properties are replicated for each language. $translation = $entity->getTranslation($langcode, FALSE); diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 8af2040..54051a6 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -287,7 +287,7 @@ public function language() { $language = language_load($this->langcode); if (!$language) { // Make sure we return a proper language object. - $language = new Language(array('langcode' => Language::LANGCODE_NOT_SPECIFIED)); + $language = new Language(array('id' => Language::LANGCODE_NOT_SPECIFIED)); } return $language; } @@ -318,7 +318,7 @@ public function getTranslationLanguages($include_default = TRUE) { // @todo: Replace by EntityNG implementation once all entity types have been // converted to use the entity field API. $default_language = $this->language(); - $languages = array($default_language->langcode => $default_language); + $languages = array($default_language->id => $default_language); $entity_info = $this->entityInfo(); if ($entity_info['fieldable']) { @@ -336,7 +336,7 @@ public function getTranslationLanguages($include_default = TRUE) { } if (empty($include_default)) { - unset($languages[$default_language->langcode]); + unset($languages[$default_language->id]); } return $languages; diff --git a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php index 448d434..e51f121 100644 --- a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php +++ b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php @@ -138,7 +138,7 @@ public function &__get($name) { // Language::LANGCODE_DEFAULT. This is necessary as EntityNG always keys // default language values with Language::LANGCODE_DEFAULT while field API // expects them to be keyed by langcode. - $langcode = $this->decorated->language()->langcode; + $langcode = $this->decorated->language()->id; if ($langcode != Language::LANGCODE_DEFAULT && isset($this->decorated->values[$name]) && is_array($this->decorated->values[$name])) { if (isset($this->decorated->values[$name][Language::LANGCODE_DEFAULT]) && !isset($this->decorated->values[$name][$langcode])) { $this->decorated->values[$name][$langcode] = &$this->decorated->values[$name][Language::LANGCODE_DEFAULT]; @@ -172,7 +172,7 @@ public function __set($name, $value) { // with Language::LANGCODE_DEFAULT while field API expects them to be // keyed by langcode. foreach ($value as $langcode => $data) { - if ($langcode != Language::LANGCODE_DEFAULT && $langcode == $this->decorated->language()->langcode) { + if ($langcode != Language::LANGCODE_DEFAULT && $langcode == $this->decorated->language()->id) { $value[Language::LANGCODE_DEFAULT] = $data; unset($value[$langcode]); } diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 2153250..9ad27f5 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -188,7 +188,7 @@ public function form(array $form, array &$form_state) { // new entities. $form['langcode'] = array( '#type' => 'value', - '#value' => !$entity->isNew() ? $entity->langcode : language_default()->langcode, + '#value' => !$entity->isNew() ? $entity->langcode : language_default()->id, ); } return $form; @@ -290,7 +290,7 @@ protected function actions(array $form, array &$form_state) { */ public function validate(array $form, array &$form_state) { $entity = $this->buildEntity($form, $form_state); - $entity_langcode = $entity->language()->langcode; + $entity_langcode = $entity->language()->id; $violations = array(); @@ -402,7 +402,7 @@ public function getFormLangcode(array $form_state) { // If no form langcode was provided we default to the current content // language and inspect existing translations to find a valid fallback, // if any. - $langcode = language(Language::TYPE_CONTENT)->langcode; + $langcode = language(Language::TYPE_CONTENT)->id; $fallback = language_multilingual() ? language_fallback_get_candidates() : array(); while (!empty($langcode) && !isset($translations[$langcode])) { $langcode = array_shift($fallback); @@ -411,14 +411,14 @@ public function getFormLangcode(array $form_state) { // If the site is not multilingual or no translation for the given form // language is available, fall back to the entity language. - return !empty($langcode) ? $langcode : $entity->language()->langcode; + return !empty($langcode) ? $langcode : $entity->language()->id; } /** * Implements \Drupal\Core\Entity\EntityFormControllerInterface::isDefaultFormLangcode(). */ public function isDefaultFormLangcode(array $form_state) { - return $this->getFormLangcode($form_state) == $this->entity->language()->langcode; + return $this->getFormLangcode($form_state) == $this->entity->language()->id; } /** @@ -453,7 +453,7 @@ protected function submitEntityLanguage(array $form, array &$form_state) { // entity language as the new language for fields to handle any language // change. Otherwise the current form language is the proper value, since // in this case it is not supposed to change. - $current_langcode = $entity->language()->langcode == $form_langcode ? $form_state['values']['langcode'] : $form_langcode; + $current_langcode = $entity->language()->id == $form_langcode ? $form_state['values']['langcode'] : $form_langcode; foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) { $field_name = $instance['field_name']; diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 648ec98..aa9f688 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -115,7 +115,7 @@ public function __construct(\Traversable $namespaces, ContainerInterface $contai $this->discovery = new AnnotatedClassDiscovery('Core/Entity', $namespaces, $annotation_namespaces, 'Drupal\Core\Entity\Annotation\EntityType'); $this->discovery = new InfoHookDecorator($this->discovery, 'entity_info'); $this->discovery = new AlterDecorator($this->discovery, 'entity_info'); - $this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->langcode, 'cache', CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE)); + $this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id, 'cache', CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE)); $this->factory = new DefaultFactory($this->discovery); $this->container = $container; @@ -370,7 +370,7 @@ public function getAdminPath($entity_type, $bundle) { public function getFieldDefinitions($entity_type, $bundle = NULL) { if (!isset($this->entityFieldInfo[$entity_type])) { // First, try to load from cache. - $cid = 'entity_field_definitions:' . $entity_type . ':' . $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->langcode; + $cid = 'entity_field_definitions:' . $entity_type . ':' . $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id; if ($cache = $this->cache->get($cid)) { $this->entityFieldInfo[$entity_type] = $cache->data; } diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index a45c55a..8b73f12 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -237,7 +237,7 @@ protected function getTranslatedField($property_name, $langcode) { } // @todo Remove this once the BC decorator is gone. elseif ($property_name != 'langcode') { - $default_langcode = $this->language()->langcode; + $default_langcode = $this->language()->id; if ($langcode == Language::LANGCODE_DEFAULT && isset($this->values[$property_name][$default_langcode])) { $value = $this->values[$property_name][$default_langcode]; } @@ -349,7 +349,7 @@ public function language() { } if (empty($this->language)) { // Make sure we return a proper language object. - $this->language = new Language(array('langcode' => Language::LANGCODE_NOT_SPECIFIED)); + $this->language = new Language(array('id' => Language::LANGCODE_NOT_SPECIFIED)); } } return $this->language; @@ -374,7 +374,7 @@ public function onChange($property_name) { public function getTranslation($langcode, $strict = TRUE) { // If the default language is Language::LANGCODE_NOT_SPECIFIED, the entity is not // translatable, so we use Language::LANGCODE_DEFAULT. - if ($langcode == Language::LANGCODE_DEFAULT || in_array($this->language()->langcode, array(Language::LANGCODE_NOT_SPECIFIED, $langcode))) { + if ($langcode == Language::LANGCODE_DEFAULT || in_array($this->language()->id, array(Language::LANGCODE_NOT_SPECIFIED, $langcode))) { // No translation needed, return the entity. return $this; } @@ -438,7 +438,7 @@ public function getTranslationLanguages($include_default = TRUE) { unset($translations[Language::LANGCODE_DEFAULT]); if ($include_default) { - $translations[$this->language()->langcode] = TRUE; + $translations[$this->language()->id] = TRUE; } // Now load language objects based upon translation langcodes. return array_intersect_key(language_list(Language::STATE_ALL), $translations); diff --git a/core/lib/Drupal/Core/Entity/EntityRenderController.php b/core/lib/Drupal/Core/Entity/EntityRenderController.php index d202636..cd92f52 100644 --- a/core/lib/Drupal/Core/Entity/EntityRenderController.php +++ b/core/lib/Drupal/Core/Entity/EntityRenderController.php @@ -96,7 +96,7 @@ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = N */ public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = language(Language::TYPE_CONTENT)->langcode; + $langcode = language(Language::TYPE_CONTENT)->id; } // Build the view modes and display objects. diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 0b9bbad..8b385ca 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -55,7 +55,7 @@ public function onRespond(FilterResponseEvent $event) { $response->headers->set('X-UA-Compatible', 'IE=edge,chrome=1', FALSE); // Set the Content-language header. - $response->headers->set('Content-language', $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->langcode); + $response->headers->set('Content-language', $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id); // Because pages are highly dynamic, set the last-modified time to now // since the page is in fact being regenerated right now. diff --git a/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php index 518e66d..d50022d 100644 --- a/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php @@ -59,7 +59,7 @@ public function onKernelRequestLanguage(GetResponseEvent $event) { $this->languageManager->setRequest($event->getRequest()); // After the language manager has initialized, set the default langcode // for the string translations. - $langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->langcode; + $langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id; $this->translation->setDefaultLangcode($langcode); } } diff --git a/core/lib/Drupal/Core/Language/Language.php b/core/lib/Drupal/Core/Language/Language.php index 01eb199..8296c18 100644 --- a/core/lib/Drupal/Core/Language/Language.php +++ b/core/lib/Drupal/Core/Language/Language.php @@ -19,7 +19,7 @@ class Language { // Properties within the Language are set up as the default language. public $name = ''; - public $langcode = ''; + public $id = ''; public $direction = Language::DIRECTION_LTR; public $weight = 0; public $default = FALSE; @@ -119,17 +119,17 @@ class Language { public function __construct(array $options = array()) { // Set all the provided properties for the language. foreach ($options as $name => $value) { - $this->$name = $value; + $this->{$name} = $value; } // If some options were not set, set sane defaults of a predefined language. if (!isset($options['name']) || !isset($options['direction'])) { $predefined = LanguageManager::getStandardLanguageList(); - if (isset($predefined[$this->langcode])) { + if (isset($predefined[$this->id])) { if (!isset($options['name'])) { - $this->name = $predefined[$this->langcode][0]; + $this->name = $predefined[$this->id][0]; } - if (!isset($options['direction']) && isset($predefined[$this->langcode][2])) { - $this->direction = $predefined[$this->langcode][2]; + if (!isset($options['direction']) && isset($predefined[$this->id][2])) { + $this->direction = $predefined[$this->id][2]; } } } @@ -146,4 +146,22 @@ public function extend($obj) { $this->$var = $value; } } + + /** + * Sort language objects. + * + * @param array $languages + * The array of language objects keyed by langcode. + */ + public static function sort($languages) { + uasort($languages, function ($a, $b) { + $a_weight = isset($a->weight) ? $a->weight : 0; + $b_weight = isset($b->weight) ? $b->weight : 0; + if ($a_weight == $b_weight) { + return strnatcasecmp($a->name, $b->name); + } + return ($a_weight < $b_weight) ? -1 : 1; + }); + } + } diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index 01f1d50..d13f6f6 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -157,13 +157,14 @@ protected function getLanguageTypes() { */ protected function getLanguageDefault() { $default_info = variable_get('language_default', array( - 'langcode' => 'en', + 'id' => 'en', 'name' => 'English', 'direction' => 0, 'weight' => 0, 'locked' => 0, )); - return new Language($default_info + array('default' => TRUE)); + $default_info['default'] = TRUE; + return new Language($default_info); } /** diff --git a/core/lib/Drupal/Core/Path/AliasManager.php b/core/lib/Drupal/Core/Path/AliasManager.php index 17657e0..91805cb 100644 --- a/core/lib/Drupal/Core/Path/AliasManager.php +++ b/core/lib/Drupal/Core/Path/AliasManager.php @@ -103,7 +103,7 @@ public function getSystemPath($path, $path_language = 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. - $path_language = $path_language ?: $this->languageManager->getLanguage(Language::TYPE_URL)->langcode; + $path_language = $path_language ?: $this->languageManager->getLanguage(Language::TYPE_URL)->id; $original_path = $path; // Lookup the path alias first. if (!empty($path) && $source = $this->lookupPathSource($path, $path_language)) { @@ -121,7 +121,7 @@ public function getPathAlias($path, $path_language = 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. - $path_language = $path_language ?: $this->languageManager->getLanguage(Language::TYPE_URL)->langcode; + $path_language = $path_language ?: $this->languageManager->getLanguage(Language::TYPE_URL)->id; $result = $path; if (!empty($path) && $alias = $this->lookupPathAlias($path, $path_language)) { $result = $alias; diff --git a/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php b/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php index c663cf1..cfcf32e 100644 --- a/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php +++ b/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php @@ -44,7 +44,7 @@ public function processInbound($path, Request $request) { * Implements Drupal\Core\PathProcessor\OutboundPathProcessorInterface::processOutbound(). */ public function processOutbound($path, &$options = array(), Request $request = NULL) { - $langcode = isset($options['language']) ? $options['language']->langcode : NULL; + $langcode = isset($options['language']) ? $options['language']->id : NULL; $path = $this->aliasManager->getPathAlias($path, $langcode); return $path; } diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index 6377ee6..7a1cdac 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -120,7 +120,7 @@ public function setCacheBackend(CacheBackendInterface $cache_backend, LanguageMa $this->languageManager = $language_manager; $this->cacheBackend = $cache_backend; $this->cacheKeyPrefix = $cache_key_prefix; - $this->cacheKey = $cache_key_prefix . ':' . $language_manager->getLanguage(Language::TYPE_INTERFACE)->langcode; + $this->cacheKey = $cache_key_prefix . ':' . $language_manager->getLanguage(Language::TYPE_INTERFACE)->id; } /** diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php index 63e543e..130ee9d 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php @@ -50,7 +50,7 @@ class TranslationManager implements TranslatorInterface { public function __construct() { // @todo Inject language_manager or config system after language_default // variable is converted to CMI. - $this->defaultLangcode = language_default()->langcode; + $this->defaultLangcode = language_default()->id; } /** diff --git a/core/lib/Drupal/Core/TypedData/Type/Language.php b/core/lib/Drupal/Core/TypedData/Type/Language.php index b910216..1d086f2 100644 --- a/core/lib/Drupal/Core/TypedData/Type/Language.php +++ b/core/lib/Drupal/Core/TypedData/Type/Language.php @@ -39,11 +39,11 @@ class Language extends TypedData { */ public function getValue() { if (!empty($this->definition['settings']['langcode source'])) { - $this->langcode = $this->parent->__get($this->definition['settings']['langcode source']); + $this->id = $this->parent->__get($this->definition['settings']['langcode source']); } - if ($this->langcode) { - $language = language_load($this->langcode); - return $language ?: new LanguageObject(array('langcode' => $this->langcode)); + if ($this->id) { + $language = language_load($this->id); + return $language ?: new LanguageObject(array('id' => $this->id)); } } @@ -55,7 +55,7 @@ public function getValue() { public function setValue($value, $notify = TRUE) { // Support passing language objects. if (is_object($value)) { - $value = $value->langcode; + $value = $value->id; } elseif (isset($value) && !is_scalar($value)) { throw new InvalidArgumentException('Value is no valid langcode or language object.'); @@ -69,7 +69,7 @@ public function setValue($value, $notify = TRUE) { if ($notify && isset($this->parent)) { $this->parent->onChange($this->name); } - $this->langcode = $value; + $this->id = $value; } } diff --git a/core/lib/Drupal/Core/Validation/DrupalTranslator.php b/core/lib/Drupal/Core/Validation/DrupalTranslator.php index ecc6781..df14d94 100644 --- a/core/lib/Drupal/Core/Validation/DrupalTranslator.php +++ b/core/lib/Drupal/Core/Validation/DrupalTranslator.php @@ -56,7 +56,7 @@ public function setLocale($locale) { * Implements \Symfony\Component\Translation\TranslatorInterface::getLocale(). */ public function getLocale() { - return $this->locale ? $this->locale : language(Language::TYPE_INTERFACE)->langcode; + return $this->locale ? $this->locale : language(Language::TYPE_INTERFACE)->id; } /** diff --git a/core/modules/action/lib/Drupal/action/Plugin/Action/EmailAction.php b/core/modules/action/lib/Drupal/action/Plugin/Action/EmailAction.php index 91432ab..921b91a 100644 --- a/core/modules/action/lib/Drupal/action/Plugin/Action/EmailAction.php +++ b/core/modules/action/lib/Drupal/action/Plugin/Action/EmailAction.php @@ -89,7 +89,7 @@ public function execute($entity = NULL) { $langcode = user_preferred_langcode($recipient_account); } else { - $langcode = language_default()->langcode; + $langcode = language_default()->id; } $params = array('context' => $this->configuration); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php b/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php index 1e77d7c..ef25376 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php @@ -35,7 +35,7 @@ public function form(array $form, array &$form_state) { $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', - '#default_value' => $feed->language()->langcode, + '#default_value' => $feed->language()->id, '#languages' => Language::STATE_ALL, ); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php index 12e41cd..2aa6731 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php @@ -39,7 +39,7 @@ public function __construct($type, \Traversable $namespaces) { ); $this->discovery = new AnnotatedClassDiscovery("aggregator/$type", $namespaces, $annotation_namespaces, $type_annotations[$type]); - $this->discovery = new CacheDecorator($this->discovery, "aggregator_$type:" . language(Language::TYPE_INTERFACE)->langcode); + $this->discovery = new CacheDecorator($this->discovery, "aggregator_$type:" . language(Language::TYPE_INTERFACE)->id); $this->factory = new DefaultFactory($this->discovery); } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php index 79d9d07..8373fa9 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php @@ -128,7 +128,7 @@ public function process(Feed $feed) { $entry = reset($entry); } else { - $entry = entity_create('aggregator_item', array('langcode' => $feed->language()->langcode)); + $entry = entity_create('aggregator_item', array('langcode' => $feed->language()->id)); } if ($item['timestamp']) { $entry->timestamp->value = $item['timestamp']; diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedLanguageTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedLanguageTest.php index 611638a..d297abc 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedLanguageTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedLanguageTest.php @@ -43,7 +43,7 @@ public function setUp() { $this->langcodes = array(language_load('en')); for ($i = 1; $i < 3; ++$i) { $language = new Language(array( - 'langcode' => 'l' . $i, + 'id' => 'l' . $i, 'name' => $this->randomString(), )); language_save($language); @@ -57,12 +57,12 @@ public function setUp() { public function testFeedLanguage() { $feeds = array(); // Create feeds. - $feeds[1] = $this->createFeed(NULL, array('langcode' => $this->langcodes[1]->langcode)); - $feeds[2] = $this->createFeed(NULL, array('langcode' => $this->langcodes[2]->langcode)); + $feeds[1] = $this->createFeed(NULL, array('langcode' => $this->langcodes[1]->id)); + $feeds[2] = $this->createFeed(NULL, array('langcode' => $this->langcodes[2]->id)); // Make sure that the language has been assigned. - $this->assertEqual($feeds[1]->language()->langcode, $this->langcodes[1]->langcode); - $this->assertEqual($feeds[2]->language()->langcode, $this->langcodes[2]->langcode); + $this->assertEqual($feeds[1]->language()->id, $this->langcodes[1]->id); + $this->assertEqual($feeds[2]->language()->id, $this->langcodes[2]->id); // Create example nodes to create feed items from and then update the feeds. $this->createSampleNodes(); @@ -74,7 +74,7 @@ public function testFeedLanguage() { $items = entity_load_multiple_by_properties('aggregator_item', array('fid' => $feed->id())); $this->assertTrue(count($items) > 0, 'Feed items were created.'); foreach ($items as $item) { - $this->assertEqual($item->language()->langcode, $feed->language()->langcode); + $this->assertEqual($item->language()->id, $feed->language()->id); } } } diff --git a/core/modules/block/block.module b/core/modules/block/block.module index ca13d32..c7b4331 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -621,8 +621,8 @@ function block_language_delete($language) { // Remove the block visibility settings for the deleted language. foreach (entity_load_multiple('block') as $block_id => $block) { $visibility = $block->get('visibility'); - if (isset($visibility['language']['langcodes'][$language->langcode])) { - unset($visibility['language']['langcodes'][$language->langcode]); + if (isset($visibility['language']['langcodes'][$language->id])) { + unset($visibility['language']['langcodes'][$language->id]); $block->set('visibility', $visibility); $block->save(); } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php index cf872c3..2f18d5b 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php @@ -69,7 +69,7 @@ public function form(array $form, array &$form_state) { // Set the correct default language. if ($block->isNew() && !empty($language_configuration['langcode'])) { $language_default = language($language_configuration['langcode']); - $block->langcode->value = $language_default->langcode; + $block->langcode->value = $language_default->id; } $form['langcode'] = array( diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php index 35f4b98..37dbf79 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php @@ -66,7 +66,7 @@ public function testCustomBlockTypeCreation() { $this->assertTrue($block_type, 'The new block type has been created.'); // Check that the block type was created in site default language. - $default_langcode = language_default()->langcode; + $default_langcode = language_default()->id; $this->assertEqual($block_type->langcode, $default_langcode); } diff --git a/core/modules/block/lib/Drupal/block/BlockAccessController.php b/core/modules/block/lib/Drupal/block/BlockAccessController.php index 6df97d7..1584ae3 100644 --- a/core/modules/block/lib/Drupal/block/BlockAccessController.php +++ b/core/modules/block/lib/Drupal/block/BlockAccessController.php @@ -87,7 +87,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A // Language visibility settings. if (!empty($visibility['language']['langcodes']) && array_filter($visibility['language']['langcodes'])) { - if (empty($visibility['language']['langcodes'][language($visibility['language']['language_type'])->langcode])) { + if (empty($visibility['language']['langcodes'][language($visibility['language']['language_type'])->id])) { return FALSE; } } diff --git a/core/modules/block/lib/Drupal/block/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php index 828c5d4..f562a68 100644 --- a/core/modules/block/lib/Drupal/block/BlockFormController.php +++ b/core/modules/block/lib/Drupal/block/BlockFormController.php @@ -116,7 +116,7 @@ public function form(array $form, array &$form_state) { foreach ($languages as $language) { // @todo $language->name is not wrapped with t(), it should be replaced // by CMI translation implementation. - $langcodes_options[$language->langcode] = $language->name; + $langcodes_options[$language->id] = $language->name; } $form['visibility']['language'] = array( '#type' => 'details', diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageCacheTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageCacheTest.php index 1dea798..126aff0 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageCacheTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageCacheTest.php @@ -44,7 +44,7 @@ public function setUp() { $this->langcodes = array(language_load('en')); for ($i = 1; $i < 3; ++$i) { $language = new Language(array( - 'langcode' => 'l' . $i, + 'id' => 'l' . $i, 'name' => $this->randomString(), )); language_save($language); diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php index 5990b2f..93b00f5 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php @@ -96,7 +96,7 @@ protected function createTests() { 'id' => 'stark.test_block', 'weight' => '', 'status' => '1', - 'langcode' => language_default()->langcode, + 'langcode' => language_default()->id, 'region' => '-1', 'plugin' => 'test_html_id', 'settings' => array( diff --git a/core/modules/book/book.module b/core/modules/book/book.module index d577bd3..f548952 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -1129,7 +1129,7 @@ function template_preprocess_book_export_html(&$variables) { // HTML element attributes. $attributes = array(); - $attributes['lang'] = $language_interface->langcode; + $attributes['lang'] = $language_interface->id; $attributes['dir'] = $language_interface->direction ? 'rtl' : 'ltr'; $variables['html_attributes'] = new Attribute($attributes); } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php index 9f40120..6a1a74a 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php @@ -176,7 +176,7 @@ public function getJSSettings(EditorEntity $editor) { 'toolbar' => $this->buildToolbarJSSetting($editor), 'contentsCss' => $this->buildContentsCssJSSetting($editor), 'extraPlugins' => implode(',', array_keys($external_plugins)), - 'language' => $language_interface->langcode, + 'language' => $language_interface->id, // Configure CKEditor to not load styles.js. The StylesCombo plugin will // set stylesSet according to the user's settings, if the "Styles" button // is enabled. We cannot get rid of this until CKEditor will stop loading diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index e2040d5..e48967f 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -154,7 +154,7 @@ public function form(array $form, array &$form_state) { // set. if ($comment->isNew()) { $language_content = language(Language::TYPE_CONTENT); - $comment->langcode->value = $language_content->langcode; + $comment->langcode->value = $language_content->id; } // Add internal comment properties. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php index 608a8a4..0880901 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php @@ -62,8 +62,8 @@ function testCommentTokenReplacement() { $tests['[comment:body]'] = $comment->comment_body->processed; $tests['[comment:url]'] = url('comment/' . $comment->id(), $url_options + array('fragment' => 'comment-' . $comment->id())); $tests['[comment:edit-url]'] = url('comment/' . $comment->id() . '/edit', $url_options); - $tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->created->value, 2, $language_interface->langcode); - $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->changed->value, 2, $language_interface->langcode); + $tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->created->value, 2, $language_interface->id); + $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->changed->value, 2, $language_interface->id); $tests['[comment:parent:cid]'] = $comment->pid->target_id; $tests['[comment:parent:title]'] = check_plain($parent_comment->subject->value); $tests['[comment:node:nid]'] = $comment->nid->target_id; @@ -75,7 +75,7 @@ function testCommentTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Sanitized comment token %token replaced.', array('%token' => $input))); } @@ -91,7 +91,7 @@ function testCommentTokenReplacement() { $tests['[comment:author:name]'] = $this->admin_user->name; foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->id, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input))); } @@ -104,7 +104,7 @@ function testCommentTokenReplacement() { $tests['[node:comment-count-new]'] = 2; foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('node' => $node), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('node' => $node), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index 09fd53b..faaccde 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -35,7 +35,7 @@ public static function getInfo() { * Tests CRUD operations. */ function testCRUD() { - $default_langcode = language_default()->langcode; + $default_langcode = language_default()->id; // Verify default properties on a newly created empty entity. $empty = entity_create('config_test', array()); $this->assertIdentical($empty->id, NULL); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php index 6296ed5..9184bfb 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php @@ -58,7 +58,7 @@ function testImport() { 'weight' => '0', 'style' => '', 'status' => '1', - 'langcode' => language_default()->langcode, + 'langcode' => language_default()->id, 'protected_property' => '', ); $staging->write($dynamic_name, $original_dynamic_data); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php index aa133d5..05d8919 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php @@ -149,7 +149,7 @@ function testNew() { 'weight' => '0', 'style' => '', 'status' => '1', - 'langcode' => language_default()->langcode, + 'langcode' => language_default()->id, 'protected_property' => '', ); $staging->write($dynamic_name, $original_dynamic_data); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php index 20ef9f0..79f22a9 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php @@ -64,18 +64,18 @@ function testConfigLocaleOverride() { */ function testConfigLocaleUserOverride() { $this->installSchema('system', 'variable'); - $this->installSchema('language', 'language'); + $this->installConfig(array('language')); language_save(new Language(array( 'name' => 'French', - 'langcode' => 'fr', + 'id' => 'fr', ))); language_save(new Language(array( 'name' => 'English', - 'langcode' => 'en', + 'id' => 'en', ))); language_save(new Language(array( 'name' => 'German', - 'langcode' => 'de', + 'id' => 'de', ))); $this->installSchema('user', 'users'); @@ -154,18 +154,18 @@ function testConfigLocaleUserOverride() { */ function testConfigLocaleLanguageOverride() { $this->installSchema('system', 'variable'); - $this->installSchema('language', 'language'); + $this->installConfig(array('language')); language_save(new Language(array( 'name' => 'French', - 'langcode' => 'fr', + 'id' => 'fr', ))); language_save(new Language(array( 'name' => 'English', - 'langcode' => 'en', + 'id' => 'en', ))); language_save(new Language(array( 'name' => 'German', - 'langcode' => 'de', + 'id' => 'de', ))); $language = language_load('fr'); @@ -231,10 +231,10 @@ function testConfigLocaleUserAndGlobalOverride() { $conf['config_test.system']['404'] = 'global herp'; $this->installSchema('system', 'variable'); - $this->installSchema('language', 'language'); + $this->installConfig(array('language')); language_save(new Language(array( 'name' => 'French', - 'langcode' => 'fr', + 'id' => 'fr', ))); $this->installSchema('user', 'users'); diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 5d26c83..2d027c1 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -277,14 +277,14 @@ function contact_mail($key, &$message, $params) { $variables['!sender-url'] = $params['sender']->mail; } - $options = array('langcode' => $language->langcode); + $options = array('langcode' => $language->id); switch ($key) { case 'page_mail': case 'page_copy': $message['subject'] .= t('[!category] !subject', $variables, $options); $message['body'][] = t("!sender-name (!sender-url) sent a message using the contact form at !form-url.", $variables, $options); - $build = entity_view($contact_message, 'mail', $language->langcode); + $build = entity_view($contact_message, 'mail', $language->id); $message['body'][] = drupal_render($build); break; @@ -303,7 +303,7 @@ function contact_mail($key, &$message, $params) { $message['body'][] = t('Hello !recipient-name,', $variables, $options); $message['body'][] = t("!sender-name (!sender-url) has sent you a message via your contact form at !site-name.", $variables, $options); $message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !recipient-edit-url.", $variables, $options); - $build = entity_view($contact_message, 'mail', $language->langcode); + $build = entity_view($contact_message, 'mail', $language->id); $message['body'][] = drupal_render($build); break; } diff --git a/core/modules/contact/lib/Drupal/contact/MessageFormController.php b/core/modules/contact/lib/Drupal/contact/MessageFormController.php index f64dbe0..bf807a6 100644 --- a/core/modules/contact/lib/Drupal/contact/MessageFormController.php +++ b/core/modules/contact/lib/Drupal/contact/MessageFormController.php @@ -159,7 +159,7 @@ public function save(array $form, array &$form_state) { $params['contact_category'] = $category; $to = implode(', ', $category->recipients); - $recipient_langcode = language_default()->langcode; + $recipient_langcode = language_default()->id; } elseif ($recipient = $message->getPersonalRecipient()) { // Send to the user in the user's preferred language. @@ -177,14 +177,14 @@ public function save(array $form, array &$form_state) { // If requested, send a copy to the user, using the current language. if ($message->copySender()) { - drupal_mail('contact', $key_prefix . '_copy', $sender->mail, $language_interface->langcode, $params, $sender->mail); + drupal_mail('contact', $key_prefix . '_copy', $sender->mail, $language_interface->id, $params, $sender->mail); } // If configured, send an auto-reply, using the current language. if (!$message->isPersonal() && $category->reply) { // User contact forms do not support an auto-reply message, so this // message always originates from the site. - drupal_mail('contact', 'page_autoreply', $sender->mail, $language_interface->langcode, $params); + drupal_mail('contact', 'page_autoreply', $sender->mail, $language_interface->id, $params); } \Drupal::service('flood')->register('contact', config('contact.settings')->get('flood.interval')); diff --git a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php index a62d0a6..83786c9 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php @@ -110,7 +110,7 @@ function testSiteWideContact() { // Check that the category was created in site default language. $langcode = config('contact.category.' . $id)->get('langcode'); - $default_langcode = language_default()->langcode; + $default_langcode = language_default()->id; $this->assertEqual($langcode, $default_langcode); // Make sure the newly created category is included in the list of categories. diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 9755c86..01c271f 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -535,7 +535,7 @@ function content_translation_translatable_batch($translatable, $field_name, &$co $context['sandbox']['max_entity_type'][$entity_type] -= count($result); $context['sandbox']['progress_entity_type'][$entity_type]++; $context['sandbox']['progress']++; - $langcode = $entity->language()->langcode; + $langcode = $entity->language()->id; // Skip process for language neutral entities. if ($langcode == Language::LANGCODE_NOT_SPECIFIED) { diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 2de5947..84fbed5 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -316,7 +316,7 @@ function content_translation_add_access(EntityInterface $entity, Language $sourc $target = !empty($target) ? $target : language(Language::TYPE_CONTENT); $translations = $entity->getTranslationLanguages(); $languages = language_list(); - return $source->langcode != $target->langcode && isset($languages[$source->langcode]) && isset($languages[$target->langcode]) && !isset($translations[$target->langcode]) && content_translation_access($entity, 'create'); + return $source->id != $target->id && isset($languages[$source->id]) && isset($languages[$target->id]) && !isset($translations[$target->id]) && content_translation_access($entity, 'create'); } /** @@ -332,7 +332,7 @@ function content_translation_edit_access(EntityInterface $entity, Language $lang $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); $translations = $entity->getTranslationLanguages(); $languages = language_list(); - return isset($languages[$language->langcode]) && $language->langcode != $entity->language()->langcode && isset($translations[$language->langcode]) && content_translation_access($entity, 'update'); + return isset($languages[$language->id]) && $language->id != $entity->language()->id && isset($translations[$language->id]) && content_translation_access($entity, 'update'); } /** @@ -348,7 +348,7 @@ function content_translation_delete_access(EntityInterface $entity, Language $la $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); $translations = $entity->getTranslationLanguages(); $languages = language_list(); - return isset($languages[$language->langcode]) && $language->langcode != $entity->language()->langcode && isset($translations[$language->langcode]) && content_translation_access($entity, 'delete'); + return isset($languages[$language->id]) && $language->id != $entity->language()->id && isset($translations[$language->id]) && content_translation_access($entity, 'delete'); } /** @@ -645,7 +645,7 @@ function content_translation_field_language_alter(&$display_language, $context) $instances = field_info_instances($entity_type, $entity->bundle()); // Avoid altering the real entity. $entity = clone($entity); - $entity_langcode = $entity->language()->langcode; + $entity_langcode = $entity->language()->id; foreach ($entity->translation as $langcode => $translation) { if ($langcode == $context['langcode'] || !content_translation_view_access($entity, $langcode)) { diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc index 5bc9501..ec03b45 100644 --- a/core/modules/content_translation/content_translation.pages.inc +++ b/core/modules/content_translation/content_translation.pages.inc @@ -19,7 +19,7 @@ function content_translation_overview(EntityInterface $entity) { $controller = content_translation_controller($entity->entityType()); $entity_manager = Drupal::entityManager(); $languages = language_list(); - $original = $entity->language()->langcode; + $original = $entity->language()->id; $translations = $entity->getTranslationLanguages(); $field_ui = module_exists('field_ui') && user_access('administer ' . $entity->entityType() . ' fields'); @@ -50,7 +50,7 @@ function content_translation_overview(EntityInterface $entity) { foreach ($languages as $language) { $language_name = $language->name; - $langcode = $language->langcode; + $langcode = $language->id; $add_path = $base_path . '/translations/add/' . $original . '/' . $langcode; $translate_path = $base_path . '/translations/edit/' . $langcode; $delete_path = $base_path . '/translations/delete/' . $langcode; @@ -117,7 +117,7 @@ function content_translation_overview(EntityInterface $entity) { else { // No such translation in the set yet: help user to create it. $row_title = $source_name = t('n/a'); - $source = $entity->language()->langcode; + $source = $entity->language()->id; if ($source != $langcode && $controller->getTranslationAccess($entity, 'create')) { if ($translatable) { @@ -197,7 +197,7 @@ function content_translation_add_page(EntityInterface $entity, Language $source content_translation_prepare_translation($entity, $source, $target); $info = $entity->entityInfo(); $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; - $form_state['langcode'] = $target->langcode; + $form_state['langcode'] = $target->id; $form_state['content_translation']['source'] = $source; $form_state['content_translation']['target'] = $target; $controller = content_translation_controller($entity->entityType()); @@ -221,7 +221,7 @@ function content_translation_edit_page(EntityInterface $entity, Language $langua $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); $info = $entity->entityInfo(); $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; - $form_state['langcode'] = $language->langcode; + $form_state['langcode'] = $language->id; $form_state['content_translation']['translation_form'] = TRUE; return Drupal::entityManager()->getForm($entity, $operation, $form_state); } @@ -241,8 +241,8 @@ function content_translation_prepare_translation(EntityInterface $entity, Langua $instances = field_info_instances($entity->entityType(), $entity->bundle()); $entity = $entity->getNGEntity(); if ($entity instanceof EntityNG) { - $source_translation = $entity->getTranslation($source->langcode); - $target_translation = $entity->getTranslation($target->langcode); + $source_translation = $entity->getTranslation($source->id); + $target_translation = $entity->getTranslation($target->id); foreach ($target_translation->getPropertyDefinitions() as $property_name => $definition) { // @todo The "key" part should not be needed. Remove it as soon as things // do not break. @@ -255,7 +255,7 @@ function content_translation_prepare_translation(EntityInterface $entity, Langua $field = field_info_field($field_name); if (!empty($field['translatable'])) { $value = $entity->get($field_name); - $value[$target->langcode] = isset($value[$source->langcode]) ? $value[$source->langcode] : array(); + $value[$target->id] = isset($value[$source->id]) ? $value[$source->id] : array(); $entity->set($field_name, $value); } } @@ -266,7 +266,7 @@ function content_translation_prepare_translation(EntityInterface $entity, Langua * Form constructor for the translation deletion confirmation. */ function content_translation_delete_confirm(array $form, array $form_state, EntityInterface $entity, Language $language) { - $langcode = $language->langcode; + $langcode = $language->id; $controller = content_translation_controller($entity->entityType()); return confirm_form( @@ -287,13 +287,13 @@ function content_translation_delete_confirm_submit(array $form, array &$form_sta $controller = content_translation_controller($entity->entityType()); // Remove the translated values. - $controller->removeTranslation($entity, $language->langcode); + $controller->removeTranslation($entity, $language->id); $entity->save(); // Remove any existing path alias for the removed translation. // @todo This should be taken care of by the Path module. if (module_exists('path')) { - $conditions = array('source' => $controller->getViewPath($entity), 'langcode' => $language->langcode); + $conditions = array('source' => $controller->getViewPath($entity), 'langcode' => $language->id); Drupal::service('path.crud')->delete($conditions); } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php index 5e4ad79..b437ddc 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php @@ -62,7 +62,7 @@ public function removeTranslation(EntityInterface $entity, $langcode) { * Implements ContentTranslationControllerInterface::retranslate(). */ public function retranslate(EntityInterface $entity, $langcode = NULL) { - $updated_langcode = !empty($langcode) ? $langcode : $entity->language()->langcode; + $updated_langcode = !empty($langcode) ? $langcode : $entity->language()->id; $translations = $entity->getTranslationLanguages(); foreach ($translations as $langcode => $language) { $entity->translation[$langcode]['outdated'] = $langcode != $updated_langcode; @@ -110,7 +110,7 @@ public function getTranslationAccess(EntityInterface $entity, $op) { * Implements ContentTranslationControllerInterface::getSourceLanguage(). */ public function getSourceLangcode(array $form_state) { - return isset($form_state['content_translation']['source']) ? $form_state['content_translation']['source']->langcode : FALSE; + return isset($form_state['content_translation']['source']) ? $form_state['content_translation']['source']->id : FALSE; } /** @@ -119,7 +119,7 @@ public function getSourceLangcode(array $form_state) { public function entityFormAlter(array &$form, array &$form_state, EntityInterface $entity) { $form_controller = content_translation_form_controller($form_state); $form_langcode = $form_controller->getFormLangcode($form_state); - $entity_langcode = $entity->language()->langcode; + $entity_langcode = $entity->language()->id; $source_langcode = $this->getSourceLangcode($form_state); $new_translation = !empty($source_langcode); @@ -137,7 +137,7 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac if (isset($languages[$form_langcode]) && ($has_translations || $new_translation)) { $title = $this->entityFormTitle($entity); // When editing the original values display just the entity label. - if ($form_langcode != $entity->language()->langcode) { + if ($form_langcode != $entity->language()->id) { $t_args = array('%language' => $languages[$form_langcode]->name, '%title' => $entity->label()); $title = empty($source_langcode) ? $title . ' [' . t('%language translation', $t_args) . ']' : t('Create %language translation of %title', $t_args); } @@ -166,8 +166,8 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac ), ); foreach (language_list(Language::STATE_CONFIGURABLE) as $language) { - if (isset($translations[$language->langcode])) { - $form['source_langcode']['source']['#options'][$language->langcode] = $language->name; + if (isset($translations[$language->id])) { + $form['source_langcode']['source']['#options'][$language->id] = $language->name; } } } @@ -179,8 +179,8 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac if ($language_widget && $has_translations) { $form['langcode']['#options'] = array(); foreach (language_list(Language::STATE_CONFIGURABLE) as $language) { - if (empty($translations[$language->langcode]) || $language->langcode == $entity_langcode) { - $form['langcode']['#options'][$language->langcode] = $language->name; + if (empty($translations[$language->id]) || $language->id == $entity_langcode) { + $form['langcode']['#options'][$language->id] = $language->name; } } } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php b/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php index 45a6c91..b1902f8 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php @@ -55,7 +55,7 @@ public function synchronizeFields(EntityInterface $entity, $sync_langcode, $orig // If the entity language is being changed there is nothing to synchronize. $entity_type = $entity->entityType(); $entity_unchanged = isset($entity->original) ? $entity->original : $this->entityManager->getStorageController($entity_type)->loadUnchanged($entity->id()); - if ($entity->language()->langcode != $entity_unchanged->language()->langcode) { + if ($entity->language()->id != $entity_unchanged->language()->id) { return; } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php index a454b8a..b635c45 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php @@ -94,9 +94,9 @@ function setUp() { protected function setupLanguages() { $this->langcodes = array('it', 'fr'); foreach ($this->langcodes as $langcode) { - language_save(new Language(array('langcode' => $langcode))); + language_save(new Language(array('id' => $langcode))); } - array_unshift($this->langcodes, language_default()->langcode); + array_unshift($this->langcodes, language_default()->id); } /** diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index ff28636..5ed17ff 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -790,7 +790,7 @@ function field_attach_form_validate(EntityInterface $entity, $form, &$form_state $has_violations = TRUE; // Place violations in $form_state. - $langcode = field_is_translatable($entity->entityType(), field_info_field($field_name)) ? $entity->language()->langcode : Language::LANGCODE_NOT_SPECIFIED; + $langcode = field_is_translatable($entity->entityType(), field_info_field($field_name)) ? $entity->language()->id : Language::LANGCODE_NOT_SPECIFIED; $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state); $field_state['constraint_violations'] = $field_violations; field_form_set_state($form['#parents'], $field_name, $langcode, $form_state, $field_state); diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index 932f6b2..b6b2a95 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -71,7 +71,7 @@ function _field_info_collate_types() { // The _info() hooks invoked below include translated strings, so each // language is cached separately. - $langcode = $language_interface->langcode; + $langcode = $language_interface->id; if (!isset($info)) { if ($cached = cache('field')->get("field_info_types:$langcode")) { diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 19bf6ed..ce9c5fa 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -255,7 +255,7 @@ function field_populate_default_values(EntityInterface $entity, $langcode = NULL $entity = $entity->getBCEntity(); $entity_type = $entity->entityType(); - $langcode = $langcode ?: $entity->language()->langcode; + $langcode = $langcode ?: $entity->language()->id; foreach (field_info_instances($entity_type, $entity->bundle()) as $field_name => $instance) { $field = field_info_field($field_name); $field_langcode = field_is_translatable($entity_type, $field) ? $langcode : Language::LANGCODE_NOT_SPECIFIED; diff --git a/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc index c04c218..ca33a31 100644 --- a/core/modules/field/field.multilingual.inc +++ b/core/modules/field/field.multilingual.inc @@ -220,7 +220,7 @@ function field_valid_language($langcode, $default = TRUE) { if (in_array($langcode, $languages)) { return $langcode; } - return $default ? language_default()->langcode : language(Language::TYPE_CONTENT)->langcode; + return $default ? language_default()->id : language(Language::TYPE_CONTENT)->id; } /** @@ -275,8 +275,8 @@ function field_language(EntityInterface $entity, $field_name = NULL, $langcode = // Language::LANGCODE_NOT_SPECIFIED. $display_langcode[$instance['field_name']] = Language::LANGCODE_NOT_SPECIFIED; foreach (language_list(Language::STATE_LOCKED) as $language_locked) { - if (isset($entity->{$instance['field_name']}[$language_locked->langcode])) { - $display_langcode[$instance['field_name']] = $language_locked->langcode; + if (isset($entity->{$instance['field_name']}[$language_locked->id])) { + $display_langcode[$instance['field_name']] = $language_locked->id; break; } } diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php index ca37842..bfbf092 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php @@ -40,7 +40,7 @@ public function validate() { $this->legacyCallback('validate', array(&$legacy_errors)); $entity = $this->getParent(); - $langcode = $entity->language()->langcode; + $langcode = $entity->language()->id; if (isset($legacy_errors[$this->getInstance()->getField()->id()][$langcode])) { foreach ($legacy_errors[$this->getInstance()->getField()->id()][$langcode] as $delta => $item_errors) { @@ -106,7 +106,7 @@ protected function legacyCallback($hook, $args = array()) { $callback = "{$module}_field_{$hook}"; if (function_exists($callback)) { $entity = $this->getParent(); - $langcode = $entity->language()->langcode; + $langcode = $entity->language()->id; // We need to remove the empty "prototype" item here. // @todo Revisit after http://drupal.org/node/1988492. diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php index 0f122b6..1ecd132 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php @@ -86,7 +86,7 @@ public function instanceSettingsForm(array $form, array &$form_state) { public function prepareCache() { if ($callback = $this->getLegacyCallback('load')) { $entity = $this->getParent()->getParent(); - $langcode = $entity->language()->langcode; + $langcode = $entity->language()->id; $entity_id = $entity->id(); // hook_field_attach_load() receives items keyed by entity id, and alter @@ -107,6 +107,51 @@ public function prepareCache() { } /** +<<<<<<< HEAD + * {@inherotdoc} + */ + public static function prepareView(array $entities_items) { + if ($entities_items) { + // Determine the legacy callback. + $field_type_definition = current($entities_items)->getPluginDefinition(); + $module = $field_type_definition['module']; + $callback = "{$module}_field_prepare_view"; + if (function_exists($callback)) { + $entities = array(); + $instances = array(); + $itemsBC = array(); + foreach ($entities_items as $id => $items) { + $entities[$id] = $items->getParent(); + $instances[$id] = $items->offsetGet(0)->getInstance(); + // We need to remove the empty "prototype" item here. + // @todo Revisit after http://drupal.org/node/1988492. + $items->filterEmptyValues(); + $itemsBC[$id] = $items->getValue(TRUE); + } + + // Determine the entity type, langcode and field. + $entity_type = current($entities)->entityType(); + $langcode = current($entities)->language()->id; + $field = current($instances)->getField(); + + $args = array( + $entity_type, + $entities, + $field, + $instances, + $langcode, + &$itemsBC, + ); + call_user_func_array($callback, $args); + + foreach ($entities_items as $id => $items) { + $items->setValue($itemsBC[$id]); + } + } + } + } + + /** * Returns the legacy callback for a given field type "hook". * * @param string $hook diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 0ae63b7..3604142 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -226,9 +226,9 @@ public function query($use_groupby = FALSE) { $column = $this->tableAlias . '.langcode'; // By the same reason as field_language the field might be Language::LANGCODE_NOT_SPECIFIED in reality so allow it as well. // @see this::field_langcode() - $default_langcode = language_default()->langcode; + $default_langcode = language_default()->id; $langcode = str_replace(array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'), - array(drupal_container()->get(Language::TYPE_CONTENT)->langcode, $default_langcode), + array(drupal_container()->get(Language::TYPE_CONTENT)->id, $default_langcode), $this->view->display_handler->options['field_langcode']); $placeholder = $this->placeholder(); $langcode_fallback_candidates = array($langcode); @@ -831,9 +831,9 @@ protected function addSelfTokens(&$tokens, $item) { */ function field_langcode(EntityInterface $entity) { if (field_is_translatable($entity->entityType(), $this->field_info)) { - $default_langcode = language_default()->langcode; + $default_langcode = language_default()->id; $langcode = str_replace(array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'), - array(drupal_container()->get(Language::TYPE_CONTENT)->langcode, $default_langcode), + array(drupal_container()->get(Language::TYPE_CONTENT)->id, $default_langcode), $this->view->display_handler->options['field_language']); // Give the Field Language API a chance to fallback to a different language diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php index 91a33d0..ebf9722 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php @@ -79,7 +79,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->installSchema('language', array('language')); $this->field_name = drupal_strtolower($this->randomName() . '_field_name'); @@ -104,7 +103,7 @@ function setUp() { for ($i = 0; $i < 3; ++$i) { $language = new Language(array( - 'langcode' => 'l' . $i, + 'id' => 'l' . $i, 'name' => $this->randomString(), )); language_save($language); @@ -213,7 +212,7 @@ function testTranslatableFieldSaveLoad() { // @todo Test every translation once the Entity Translation API allows for // multilingual defaults. - $langcode = $entity->language()->langcode; + $langcode = $entity->language()->id; $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $instance['default_value'], format_string('Default value correctly populated for language %language.', array('%language' => $langcode))); // Check that explicit empty values are not overridden with default values. diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php index 0893f43..8fdf064 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php @@ -87,7 +87,7 @@ function setUp() { for ($i = 0; $i < 3; ++$i) { $language = new Language(array( - 'langcode' => 'l' . $i, + 'id' => 'l' . $i, 'name' => $this->randomString(), )); language_save($language); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index c154332..36d323d 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -57,8 +57,8 @@ function testFileTokenReplacement() { $tests['[file:mime]'] = check_plain($file->getMimeType()); $tests['[file:size]'] = format_size($file->getSize()); $tests['[file:url]'] = check_plain(file_create_url($file->getFileUri())); - $tests['[file:timestamp]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->langcode); - $tests['[file:timestamp:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->langcode); + $tests['[file:timestamp]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->id); + $tests['[file:timestamp:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->id); $tests['[file:owner]'] = check_plain(user_format_name($this->admin_user)); $tests['[file:owner:uid]'] = $file->getOwner()->id(); @@ -66,7 +66,7 @@ function testFileTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Sanitized file token %token replaced.', array('%token' => $input))); } @@ -77,7 +77,7 @@ function testFileTokenReplacement() { $tests['[file:size]'] = format_size($file->getSize()); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->id, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized file token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 717d156..dd73906 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -263,7 +263,7 @@ function filter_formats($account = NULL) { // All available formats are cached for performance. if (!isset($formats['all'])) { - if ($cache = cache()->get("filter_formats:{$language_interface->langcode}")) { + if ($cache = cache()->get("filter_formats:{$language_interface->id}")) { $formats['all'] = $cache->data; } else { @@ -276,7 +276,7 @@ function filter_formats($account = NULL) { } uasort($formats['all'], 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); - cache()->set("filter_formats:{$language_interface->langcode}", $formats['all'], CacheBackendInterface::CACHE_PERMANENT, array('filter_formats' => TRUE)); + cache()->set("filter_formats:{$language_interface->id}", $formats['all'], CacheBackendInterface::CACHE_PERMANENT, array('filter_formats' => TRUE)); } } diff --git a/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php b/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php index fcf94d8..881cdf7 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php +++ b/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php @@ -33,7 +33,7 @@ public function __construct(\Traversable $namespaces) { $annotation_namespaces = array('Drupal\filter\Annotation' => $namespaces['Drupal\filter']); $this->discovery = new AnnotatedClassDiscovery('Filter', $namespaces, $annotation_namespaces, 'Drupal\filter\Annotation\Filter'); $this->discovery = new AlterDecorator($this->discovery, 'filter_info'); - $cache_key = 'filter_plugins:' . language(Language::TYPE_INTERFACE)->langcode; + $cache_key = 'filter_plugins:' . language(Language::TYPE_INTERFACE)->id; $cache_tags = array('filter_formats' => TRUE); $this->discovery = new CacheDecorator($this->discovery, $cache_key, 'cache', CacheBackendInterface::CACHE_PERMANENT, $cache_tags); } diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php index 80b9dd1..15ae75c 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php @@ -87,7 +87,7 @@ function testTextFormatCrud() { */ function verifyTextFormat($format) { $t_args = array('%format' => $format->name); - $default_langcode = language_default()->langcode; + $default_langcode = language_default()->id; // Verify filter_format_load(). $filter_format = filter_format_load($format->format); diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index e0219ff..d44da5c 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -37,7 +37,7 @@ function forum_enable() { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => t('Forums'), 'vid' => 'forums', - 'langcode' => language_default()->langcode, + 'langcode' => language_default()->id, 'description' => t('Forum navigation vocabulary'), 'hierarchy' => 1, 'module' => 'forum', @@ -68,7 +68,7 @@ function forum_enable() { // Create a default forum so forum posts can be created. $term = entity_create('taxonomy_term', array( 'name' => t('General discussion'), - 'langcode' => language_default()->langcode, + 'langcode' => language_default()->id, 'description' => '', 'parent' => array(0), 'vid' => $vocabulary->id(), diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php index 9cd6ae9..63f1da3 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -319,7 +319,7 @@ private function doAdminTests($user) { 'name' => 'Tags', 'description' => $description, 'vid' => 'tags', - 'langcode' => language_default()->langcode, + 'langcode' => language_default()->id, 'help' => $help, )); $vocabulary->save(); diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php index f435de3..725fca3 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php @@ -45,8 +45,8 @@ public function normalize($field, $format = NULL, array $context = array()) { // to the field item values. else { foreach ($entity->getTranslationLanguages() as $lang) { - $context['langcode'] = $lang->langcode == 'und' ? Language::LANGCODE_DEFAULT : $lang->langcode; - $translation = $entity->getTranslation($lang->langcode); + $context['langcode'] = $lang->id == 'und' ? Language::LANGCODE_DEFAULT : $lang->id; + $translation = $entity->getTranslation($lang->id); $translated_field = $translation->get($field_name); $normalized_field_items = array_merge($normalized_field_items, $this->normalizeFieldItems($translated_field, $format, $context)); } diff --git a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php index ae7e582..ea55fd9 100644 --- a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php +++ b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php @@ -60,19 +60,18 @@ function setUp() { parent::setUp(); $this->installSchema('system', array('variable', 'url_alias')); $this->installSchema('user', array('users')); - $this->installSchema('language', array('language')); $this->installSchema('entity_test', array('entity_test')); - $this->installConfig(array('field')); + $this->installConfig(array('field', 'language')); // Add English as a language. $english = new Language(array( - 'langcode' => 'en', + 'id' => 'en', 'name' => 'English', )); language_save($english); // Add German as a language. $german = new Language(array( - 'langcode' => 'de', + 'id' => 'de', 'name' => 'Deutsch', )); language_save($german); diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 5eda365..0a6e27c 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -719,7 +719,7 @@ function image_effect_definitions() { // hook_image_effect_info() includes translated strings, so each language is // cached separately. - $langcode = $language_interface->langcode; + $langcode = $language_interface->id; $effects = &drupal_static(__FUNCTION__); diff --git a/core/modules/language/config/language.entity.en.yml b/core/modules/language/config/language.entity.en.yml new file mode 100644 index 0000000..75b964c --- /dev/null +++ b/core/modules/language/config/language.entity.en.yml @@ -0,0 +1,8 @@ +id: en +uuid: fe61d3d1-e8d5-47a7-a21c-2841f4be3c09 +label: English +direction: '0' +weight: '0' +locked: '0' +status: '1' +langcode: en diff --git a/core/modules/language/config/language.entity.und.yml b/core/modules/language/config/language.entity.und.yml new file mode 100644 index 0000000..892ce08 --- /dev/null +++ b/core/modules/language/config/language.entity.und.yml @@ -0,0 +1,8 @@ +id: und +uuid: 87e4ef47-819b-4d89-aa4b-757f9ce5a3b2 +label: 'Not specified' +direction: '0' +weight: '1' +locked: '1' +status: '1' +langcode: en diff --git a/core/modules/language/config/language.entity.zxx.yml b/core/modules/language/config/language.entity.zxx.yml new file mode 100644 index 0000000..bb4c6fa --- /dev/null +++ b/core/modules/language/config/language.entity.zxx.yml @@ -0,0 +1,8 @@ +id: zxx +uuid: de5bb3a9-1038-4ada-ba05-05cc965ea702 +label: 'Not applicable' +direction: '0' +weight: '2' +locked: '1' +status: '1' +langcode: en diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index ee3dbd1..a7c6663 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -52,7 +52,7 @@ function language_admin_overview_form($form, &$form_state) { 'title' => t('edit'), 'href' => 'admin/config/regional/language/edit/' . $langcode, ); - if ($langcode != $default->langcode) { + if ($langcode != $default->id) { $links['delete'] = array( 'title' => t('delete'), 'href' => 'admin/config/regional/language/delete/' . $langcode, @@ -161,17 +161,17 @@ function language_admin_edit_form($form, &$form_state, $language) { */ function _language_admin_common_controls(&$form, $language = NULL) { if (!is_object($language)) { - $language = new Language(array('langcode' => NULL, 'name' => NULL,)); + $language = new Language(array('id' => NULL, 'name' => NULL,)); } - if (isset($language->langcode)) { + if (isset($language->id)) { $form['langcode_view'] = array( '#type' => 'item', '#title' => t('Language code'), - '#markup' => $language->langcode + '#markup' => $language->id ); $form['langcode'] = array( '#type' => 'value', - '#value' => $language->langcode + '#value' => $language->id ); } else { @@ -245,13 +245,13 @@ function language_admin_add_form_submit($form, &$form_state) { $langcode = $form_state['values']['langcode']; // Custom language form. $language = new Language(array( - 'langcode' => $langcode, + 'id' => $langcode, 'name' => $form_state['values']['name'], 'direction' => $form_state['values']['direction'], )); } else { - $language = new Language(array('langcode' => $langcode)); + $language = new Language(array('id' => $langcode)); } // Save the language and inform the user that it happened. $language = language_save($language); @@ -295,9 +295,9 @@ function language_admin_edit_form_submit($form, &$form_state) { * User interface for the language deletion confirmation screen. */ function language_admin_delete_form($form, &$form_state, $language) { - $langcode = $language->langcode; + $langcode = $language->id; - if (language_default()->langcode == $langcode) { + if (language_default()->id == $langcode) { drupal_set_message(t('The default language cannot be deleted.')); return new RedirectResponse(url('admin/config/regional/language', array('absolute' => TRUE))); } @@ -325,7 +325,7 @@ function language_admin_delete_form_submit($form, &$form_state) { $success = language_delete($langcode); if ($success) { - $t_args = array('%language' => $language->name, '%langcode' => $language->langcode); + $t_args = array('%language' => $language->name, '%langcode' => $language->id); drupal_set_message(t('The %language (%langcode) language has been removed.', $t_args)); } diff --git a/core/modules/language/language.api.php b/core/modules/language/language.api.php index 6f19835..cba3f96 100644 --- a/core/modules/language/language.api.php +++ b/core/modules/language/language.api.php @@ -53,7 +53,7 @@ function hook_language_delete($language) { // On nodes with this language, unset the language db_update('node') ->fields(array('language' => '')) - ->condition('language', $language->langcode) + ->condition('language', $language->id) ->execute(); } diff --git a/core/modules/language/language.install b/core/modules/language/language.install index 17828fd..066ef26 100644 --- a/core/modules/language/language.install +++ b/core/modules/language/language.install @@ -5,6 +5,9 @@ * Install, update and uninstall functions for the language module. */ +use Drupal\Component\Uuid\Uuid; +use Drupal\Core\Language\Language; + /** * Implements hook_install(). * @@ -12,14 +15,6 @@ * system on multilingual sites without needing any preliminary configuration. */ function language_install() { - // Add the default language at first so that language_list() returns this in - // language_special_languages(). - $default_language = language_save(language_default()); - $languages = language_default_locked_languages($default_language->weight); - foreach ($languages as $language) { - language_save($language); - } - // Enable URL language detection for each configurable language type. require_once DRUPAL_ROOT . '/core/includes/language.inc'; foreach (language_types_get_configurable(FALSE) as $type) { @@ -51,55 +46,6 @@ function language_uninstall() { } /** - * Implements hook_schema(). - */ -function language_schema() { - $schema['language'] = array( - 'description' => 'List of all available languages in the system.', - 'fields' => array( - 'langcode' => array( - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - 'description' => "Language code, e.g. 'de' or 'en-US'.", - ), - 'name' => array( - 'type' => 'varchar', - 'length' => 64, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Language name.', - ), - 'direction' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'description' => 'Direction of language (Left-to-Right = 0, Right-to-Left = 1).', - ), - 'weight' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'description' => 'Weight, used in lists of languages.', - ), - 'locked' => array( - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 0, - 'description' => 'A boolean indicating whether the administrator can edit or delete the language.', - ), - ), - 'primary key' => array('langcode'), - 'indexes' => array( - 'list' => array('weight', 'name'), - ), - ); - return $schema; -} - -/** * Implements hook_enable(). */ function language_enable() { diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 9d05700..bdbd15c 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -454,11 +454,11 @@ function language_get_default_langcode($entity_type, $bundle) { $language_interface = language(Language::TYPE_INTERFACE); switch ($configuration['langcode']) { case 'site_default': - $default_value = language_default()->langcode; + $default_value = language_default()->id; break; case 'current_interface': - $default_value = $language_interface->langcode; + $default_value = $language_interface->id; break; case 'authors_default': @@ -467,7 +467,7 @@ function language_get_default_langcode($entity_type, $bundle) { $default_value = $user->preferred_langcode; } else { - $default_value = $language_interface->langcode; + $default_value = $language_interface->id; } break; } @@ -484,23 +484,35 @@ function language_get_default_langcode($entity_type, $bundle) { * API function to add or update a language. * * @param $language - * Language object with properties corresponding to 'language' table columns. + * Language object with properties corresponding to the 'language' + * configuration properties. */ function language_save($language) { - $language->is_new = !(bool) db_query_range('SELECT 1 FROM {language} WHERE langcode = :langcode', 0, 1, array(':langcode' => $language->langcode))->fetchField(); + $language_entity = entity_load('language_entity', $language->id); + if (!$language_entity) { + $language_entity = entity_create('language_entity', array( + 'id' => $language->id, + )); + } + $language->is_new = $language_entity->isNew(); // Let other modules modify $language before saved. module_invoke_all('language_presave', $language); + // Assign language properties to language entity. + $language_entity->label = isset($language->name) ? $language->name : ''; + $language_entity->direction = isset($language->direction) ? $language->direction : '0'; + $language_entity->locked = isset($language->locked) ? $language->locked : '0'; + $language_entity->weight = isset($language->weight) ? $language->weight : '0'; + // Save the record and inform others about the change. - $t_args = array('%language' => $language->name, '%langcode' => $language->langcode); + $language_entity->save(); + $t_args = array('%language' => $language->name, '%langcode' => $language->id); if ($language->is_new) { - drupal_write_record('language', $language); module_invoke_all('language_insert', $language); watchdog('language', 'The %language (%langcode) language has been created.', $t_args); } else { - drupal_write_record('language', $language, array('langcode')); module_invoke_all('language_update', $language); watchdog('language', 'The %language (%langcode) language has been updated.', $t_args); } @@ -536,7 +548,13 @@ function language_save($language) { * @see language_multilingual() */ function language_update_count() { - variable_set('language_count', db_query('SELECT COUNT(langcode) FROM {language} WHERE locked = 0')->fetchField()); + $count = 0; + foreach (entity_load_multiple('language_entity') as $language) { + if (!$language->locked) { + $count++; + } + } + variable_set('language_count', $count); } /** @@ -556,9 +574,7 @@ function language_delete($langcode) { module_invoke_all('language_delete', $language); // Remove the language. - db_delete('language') - ->condition('langcode', $language->langcode) - ->execute(); + entity_delete_multiple('language_entity', array($language->id)); language_update_count(); @@ -567,7 +583,7 @@ function language_delete($langcode) { drupal_static_reset('language_list'); - $t_args = array('%language' => $language->name, '%langcode' => $language->langcode); + $t_args = array('%language' => $language->name, '%langcode' => $language->id); watchdog('language', 'The %language (%langcode) language has been removed.', $t_args); return TRUE; } @@ -725,7 +741,7 @@ function language_language_insert($language) { // Add language to the list of language domains. $domains = language_negotiation_url_domains(); - $domains[$language->langcode] = ''; + $domains[$language->id] = ''; language_negotiation_url_domains_save($domains); } @@ -737,12 +753,12 @@ function language_language_delete($language) { // Remove language from language prefix list. $prefixes = language_negotiation_url_prefixes(); - unset($prefixes[$language->langcode]); + unset($prefixes[$language->id]); language_negotiation_url_prefixes_save($prefixes); // Remove language from language domain list. $domains = language_negotiation_url_domains(); - unset($domains[$language->langcode]); + unset($domains[$language->id]); language_negotiation_url_domains_save($domains); } @@ -787,16 +803,22 @@ function language_set_browser_drupal_langcode_mappings($mappings) { * Updates locked system language weights. */ function language_update_locked_weights() { + $max_weight = 0; + // Get maximum weight to update the system languages to keep them on bottom. - $max_weight = db_query('SELECT MAX(weight) FROM {language} WHERE locked = 0')->fetchField(); + foreach (language_list(Language::STATE_CONFIGURABLE) as $language) { + if (!$language->locked && $language->weight > $max_weight) { + $max_weight = $language->weight; + } + } + // Loop locked languages to maintain the existing order. foreach (language_list(Language::STATE_LOCKED) as $language) { $max_weight++; // Update system languages weight. - db_update('language') - ->fields(array('weight' => $max_weight)) - ->condition('langcode', $language->langcode) - ->execute(); + Drupal::config('language.entity.' . $language->id) + ->set('weight', $max_weight) + ->save(); } } @@ -814,7 +836,7 @@ function language_form_system_regional_settings_alter(&$form, &$form_state) { $form['locale']['site_default_language'] = array( '#type' => 'select', '#title' => t('Default language'), - '#default_value' => $default->langcode, + '#default_value' => $default->id, '#options' => $language_options, '#description' => t('It is not recommended to change the default language on a working site. Configure the Selected language setting on the detection and selection page to change the fallback language for language selection.', array('@language-detection' => url('admin/config/regional/language/detection'))), '#weight' => -1, diff --git a/core/modules/language/language.negotiation.inc b/core/modules/language/language.negotiation.inc index 82bf713..126ec5a 100644 --- a/core/modules/language/language.negotiation.inc +++ b/core/modules/language/language.negotiation.inc @@ -61,7 +61,7 @@ * The current interface language code. */ function language_from_interface() { - return language(Language::TYPE_INTERFACE)->langcode; + return language(Language::TYPE_INTERFACE)->id; } /** @@ -175,7 +175,7 @@ function language_from_browser($languages) { // Find the best match. if ($qvalue > $max_qvalue) { - $best_match_langcode = $language->langcode; + $best_match_langcode = $language->id; $max_qvalue = $qvalue; } } @@ -287,7 +287,7 @@ function language_from_url($languages, Request $request = NULL) { list($language, $path) = language_url_split_prefix($request_path, $languages); if ($language !== FALSE) { - $language_url = $language->langcode; + $language_url = $language->id; } break; @@ -301,13 +301,13 @@ function language_from_url($languages, Request $request = NULL) { $domains = language_negotiation_url_domains(); foreach ($languages as $language) { // Skip the check if the language doesn't have a domain. - if (!empty($domains[$language->langcode])) { + if (!empty($domains[$language->id])) { // Ensure that there is exactly one protocol in the URL when checking // the hostname. - $host = 'http://' . str_replace(array('http://', 'https://'), '', $domains[$language->langcode]); + $host = 'http://' . str_replace(array('http://', 'https://'), '', $domains[$language->id]); $host = parse_url($host, PHP_URL_HOST); if ($http_host == $host) { - $language_url = $language->langcode; + $language_url = $language->id; break; } } @@ -363,11 +363,11 @@ function language_url_fallback($language = NULL, $request = NULL, $language_type // the default one, otherwise we fall back to an already detected language. $domains = language_negotiation_url_domains(); $prefixes = language_negotiation_url_prefixes(); - if (($prefix && empty($prefixes[$default->langcode])) || (!$prefix && empty($domains[$default->langcode]))) { - return $default->langcode; + if (($prefix && empty($prefixes[$default->id])) || (!$prefix && empty($domains[$default->id]))) { + return $default->id; } else { - $langcode = language($language_type)->langcode; + $langcode = language($language_type)->id; return $langcode; } } @@ -382,7 +382,7 @@ function language_switcher_url($type, $path) { $links = array(); foreach ($languages as $language) { - $links[$language->langcode] = array( + $links[$language->id] = array( 'href' => $path, 'title' => $language->name, 'language' => $language, @@ -398,7 +398,7 @@ function language_switcher_url($type, $path) { */ function language_switcher_session($type, $path) { $param = config('language.negotiation')->get('session.parameter'); - $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : language($type)->langcode; + $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : language($type)->id; $languages = language_list(); $links = array(); @@ -406,7 +406,7 @@ function language_switcher_session($type, $path) { $query = $_GET; foreach ($languages as $language) { - $langcode = $language->langcode; + $langcode = $language->id; $links[$langcode] = array( 'href' => $path, 'title' => $language->name, @@ -439,10 +439,10 @@ function language_negotiation_url_prefixes_update() { foreach (language_list() as $language) { // The prefix for this language should be updated if it's not assigned yet // or the prefix is set to the empty string. - if (empty($prefixes[$language->langcode])) { + if (empty($prefixes[$language->id])) { // For the default language, set the prefix to the empty string, // otherwise use the langcode. - $prefixes[$language->langcode] = !empty($language->default) ? '' : $language->langcode; + $prefixes[$language->id] = !empty($language->default) ? '' : $language->id; } // Otherwise we keep the configured prefix. } diff --git a/core/modules/language/language.views.inc b/core/modules/language/language.views.inc deleted file mode 100644 index 2ec7e3a..0000000 --- a/core/modules/language/language.views.inc +++ /dev/null @@ -1,108 +0,0 @@ - 'langcode', - 'title' => t('Language'), - 'help' => t('A language used in drupal.'), - ); - - $data['language']['langcode'] = array( - 'title' => t('Language code'), - 'help' => t("Language code, e.g. 'de' or 'en-US'."), - 'field' => array( - 'id' => 'standard', - ), - 'filter' => array( - 'id' => 'string' - ), - 'argument' => array( - 'id' => 'string', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - - $data['language']['name'] = array( - 'title' => t('Language name'), - 'help' => t("Language name, e.g. 'German' or 'English'."), - 'field' => array( - 'id' => 'standard', - ), - 'filter' => array( - 'id' => 'string' - ), - 'argument' => array( - 'id' => 'string', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - - $data['language']['direction'] = array( - 'title' => t('Direction'), - 'help' => t('Direction of language (Left-to-Right = 0, Right-to-Left = 1).'), - 'field' => array( - 'id' => 'numeric', - ), - 'filter' => array( - 'id' => 'numeric' - ), - 'argument' => array( - 'id' => 'numeric', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - - $data['language']['weight'] = array( - 'title' => t('Weight'), - 'help' => t('Weight, used in lists of languages.'), - 'field' => array( - 'id' => 'numeric', - ), - 'filter' => array( - 'id' => 'numeric' - ), - 'argument' => array( - 'id' => 'numeric', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - - $data['language']['locked'] = array( - 'title' => t('Locked'), - 'help' => t('A boolean indicating whether the administrator can edit or delete the language.'), - 'field' => array( - 'id' => 'boolean', - ), - 'filter' => array( - 'id' => 'boolean', - ), - 'argument' => array( - 'id' => 'numeric', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - - return $data; -} diff --git a/core/modules/language/lib/Drupal/language/Form/NegotiationUrlForm.php b/core/modules/language/lib/Drupal/language/Form/NegotiationUrlForm.php index 9a95329..e73ccdb 100644 --- a/core/modules/language/lib/Drupal/language/Form/NegotiationUrlForm.php +++ b/core/modules/language/lib/Drupal/language/Form/NegotiationUrlForm.php @@ -70,7 +70,7 @@ public function buildForm(array $form, array &$form_state) { $prefixes = language_negotiation_url_prefixes(); $domains = language_negotiation_url_domains(); foreach ($languages as $langcode => $language) { - $t_args = array('%language' => $language->name, '%langcode' => $language->langcode); + $t_args = array('%language' => $language->name, '%langcode' => $language->id); $form['prefix'][$langcode] = array( '#type' => 'textfield', '#title' => $language->default ? t('%language (%langcode) path prefix (Default language)', $t_args) : t('%language (%langcode) path prefix', $t_args), @@ -80,7 +80,7 @@ public function buildForm(array $form, array &$form_state) { ); $form['domain'][$langcode] = array( '#type' => 'textfield', - '#title' => t('%language (%langcode) domain', array('%language' => $language->name, '%langcode' => $language->langcode)), + '#title' => t('%language (%langcode) domain', array('%language' => $language->name, '%langcode' => $language->id)), '#maxlength' => 128, '#default_value' => isset($domains[$langcode]) ? $domains[$langcode] : '', ); diff --git a/core/modules/language/lib/Drupal/language/HttpKernel/PathProcessorLanguage.php b/core/modules/language/lib/Drupal/language/HttpKernel/PathProcessorLanguage.php index 2440d2f..aa3cc2b 100644 --- a/core/modules/language/lib/Drupal/language/HttpKernel/PathProcessorLanguage.php +++ b/core/modules/language/lib/Drupal/language/HttpKernel/PathProcessorLanguage.php @@ -81,7 +81,7 @@ public function processInbound($path, Request $request) { // Search prefix within enabled languages. $prefixes = $this->config->get('language.negotiation')->get('url.prefixes'); foreach ($this->languages as $language) { - if (isset($prefixes[$language->langcode]) && $prefixes[$language->langcode] == $prefix) { + if (isset($prefixes[$language->id]) && $prefixes[$language->id] == $prefix) { // Rebuild $path with the language removed. return implode('/', $args); } @@ -110,7 +110,7 @@ public function processOutbound($path, &$options = array(), Request $request = N $options['language'] = $language_url; } // We allow only enabled languages here. - elseif (is_object($options['language']) && !isset($languages[$options['language']->langcode])) { + elseif (is_object($options['language']) && !isset($languages[$options['language']->id])) { return $path; } $url_source = $this->config->get('language.negotiation')->get('url.source'); @@ -118,13 +118,13 @@ public function processOutbound($path, &$options = array(), Request $request = N // constant. if ($url_source == 'path_prefix') { $prefixes = $this->config->get('language.negotiation')->get('url.prefixes'); - if (is_object($options['language']) && !empty($prefixes[$options['language']->langcode])) { - return empty($path) ? $prefixes[$options['language']->langcode] : $prefixes[$options['language']->langcode] . '/' . $path; + if (is_object($options['language']) && !empty($prefixes[$options['language']->id])) { + return empty($path) ? $prefixes[$options['language']->id] : $prefixes[$options['language']->id] . '/' . $path; } } elseif ($url_source == 'domain') { $domains = $this->config->get('language.negotiation')->get('url.domains'); - if (is_object($options['language']) && !empty($domains[$options['language']->langcode])) { + if (is_object($options['language']) && !empty($domains[$options['language']->id])) { // Save the original base URL. If it contains a port, we need to // retain it below. @@ -135,7 +135,7 @@ public function processOutbound($path, &$options = array(), Request $request = N // Ask for an absolute URL with our modified base URL. $options['absolute'] = TRUE; - $options['base_url'] = $url_scheme . '://' . $domains[$options['language']->langcode]; + $options['base_url'] = $url_scheme . '://' . $domains[$options['language']->id]; // In case either the original base URL or the HTTP host contains a // port, retain it. diff --git a/core/modules/language/lib/Drupal/language/LanguageInterface.php b/core/modules/language/lib/Drupal/language/LanguageInterface.php new file mode 100644 index 0000000..35db887 --- /dev/null +++ b/core/modules/language/lib/Drupal/language/LanguageInterface.php @@ -0,0 +1,17 @@ +name is not wrapped with t(), it should be replaced - // by CMI translation implementation. - $langcodes_options[$language->langcode] = $language->name; + $langcodes_options[$language->id] = $language->label(); } $form['langcodes'] = array( '#type' => 'checkboxes', @@ -76,8 +74,8 @@ public function summary() { $language_names = array_reduce($language_list, function(&$result, $item) use ($selected) { // If the current item of the $language_list array is one of the selected // languages, add it to the $results array. - if (!empty($selected[$item->langcode])) { - $result[$item->langcode] = $item->name; + if (!empty($selected[$item->id])) { + $result[$item->id] = $item->name; } return $result; }, array()); @@ -103,7 +101,7 @@ public function evaluate() { $language = $this->getContextValue('language'); // Language visibility settings. if (!empty($this->configuration['langcodes'])) { - return !empty($this->configuration['langcodes'][$language->langcode]); + return !empty($this->configuration['langcodes'][$language->id]); } return TRUE; } diff --git a/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php b/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php new file mode 100644 index 0000000..4172e96 --- /dev/null +++ b/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php @@ -0,0 +1,79 @@ +installSchema('language', 'language'); // This is needed for language_default(). // @todo remove this when language_default() no longer needs variable_get(). $this->installSchema('system', 'variable'); + $this->installConfig(array('language')); // Setup English. language_save(language_default()); // Setup Italian. $language = new Language(array( - 'langcode' => 'it', + 'id' => 'it', 'name' => 'Italian', 'direction' => '0', )); diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php index 80a835d..07ea3d5 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php @@ -39,40 +39,40 @@ function testLanguageFromBrowser() { $languages = array( // In our test case, 'en' has priority over 'en-US'. 'en' => new Language(array( - 'langcode' => 'en', + 'id' => 'en', )), 'en-US' => new Language(array( - 'langcode' => 'en-US', + 'id' => 'en-US', )), // But 'fr-CA' has priority over 'fr'. 'fr-CA' => new Language(array( - 'langcode' => 'fr-CA', + 'id' => 'fr-CA', )), 'fr' => new Language(array( - 'langcode' => 'fr', + 'id' => 'fr', )), // 'es-MX' is alone. 'es-MX' => new Language(array( - 'langcode' => 'es-MX', + 'id' => 'es-MX', )), // 'pt' is alone. 'pt' => new Language(array( - 'langcode' => 'pt', + 'id' => 'pt', )), // Language codes with more then one dash are actually valid. // eh-oh-laa-laa is the official language code of the Teletubbies. 'eh-oh-laa-laa' => new Language(array( - 'langcode' => 'eh-oh-laa-laa', + 'id' => 'eh-oh-laa-laa', )), // Chinese languages. 'zh-hans' => new Language(array( - 'langcode' => 'zh-hans', + 'id' => 'zh-hans', )), 'zh-hant' => new Language(array( - 'langcode' => 'zh-hant', + 'id' => 'zh-hant', )), 'zh-hant-tw' => new Language(array( - 'langcode' => 'zh-hant', + 'id' => 'zh-hant', )), ); diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php index 1bc67da..fcec194 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php @@ -69,7 +69,7 @@ public function testDefaultLangcode() { // Add some custom languages. foreach (array('aa', 'bb', 'cc') as $language_code) { $language = new Language(array( - 'langcode' => $language_code, + 'id' => $language_code, 'name' => $this->randomName(), )); language_save($language); @@ -84,7 +84,7 @@ public function testDefaultLangcode() { language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'current_interface', 'language_show' => TRUE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); $language_interface = language(Language::TYPE_INTERFACE); - $this->assertEqual($langcode, $language_interface->langcode); + $this->assertEqual($langcode, $language_interface->id); // Site's default. $old_default = language_default(); diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php index 770337c..4bce384 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php @@ -159,7 +159,16 @@ protected function checkConfigurableLanguageWeight($state = 'by default') { * Maximum weight of configurable languages. */ protected function getHighestConfigurableLanguageWeight(){ - return db_query('SELECT MAX(weight) FROM {language} WHERE locked = 0')->fetchField(); + $max_weight = 0; + + $languages = entity_load_multiple('language_entity', NULL, TRUE); + foreach ($languages as $language) { + if (!$language->locked && $language->weight > $max_weight) { + $max_weight = $language->weight; + } + } + + return $max_weight; } } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php index 088d655..97488ed 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php @@ -64,7 +64,7 @@ function testDependencyInjectedNewLanguage() { function testDependencyInjectedNewDefaultLanguage() { // Change the language default object to different values. $new_language_default = array( - 'langcode' => 'fr', + 'id' => 'fr', 'name' => 'French', 'direction' => 0, 'weight' => 0, diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php index 570ae2a..fa718da 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php @@ -173,10 +173,10 @@ function testLanguageList() { */ function testLanguageStates() { // Add some languages, and also lock some of them. - language_save(new Language(array('name' => $this->randomName(), 'langcode' => 'l1'))); - language_save(new Language(array('name' => $this->randomName(), 'langcode' => 'l2', 'locked' => TRUE))); - language_save(new Language(array('name' => $this->randomName(), 'langcode' => 'l3'))); - language_save(new Language(array('name' => $this->randomName(), 'langcode' => 'l4', 'locked' => TRUE))); + language_save(new Language(array('name' => $this->randomName(), 'id' => 'l1'))); + language_save(new Language(array('name' => $this->randomName(), 'id' => 'l2', 'locked' => TRUE))); + language_save(new Language(array('name' => $this->randomName(), 'id' => 'l3'))); + language_save(new Language(array('name' => $this->randomName(), 'id' => 'l4', 'locked' => TRUE))); $expected_locked_languages = array('l4' => 'l4', 'l2' => 'l2', 'und' => 'und', 'zxx' => 'zxx'); $expected_all_languages = array('l4' => 'l4', 'l3' => 'l3', 'l2' => 'l2', 'l1' => 'l1', 'en' => 'en', 'und' => 'und', 'zxx' => 'zxx'); $expected_conf_languages = array('l3' => 'l3', 'l1' => 'l1', 'en' => 'en'); diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguagePathMonolingualTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguagePathMonolingualTest.php index 89a1bd6..d7f0306 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguagePathMonolingualTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguagePathMonolingualTest.php @@ -52,7 +52,7 @@ function setUp() { // Verify that French is the only language. $this->assertFalse(language_multilingual(), 'Site is mono-lingual'); - $this->assertEqual(language_default()->langcode, 'fr', 'French is the default language'); + $this->assertEqual(language_default()->id, 'fr', 'French is the default language'); // Set language detection to URL. $edit = array('language_interface[enabled][language-url]' => TRUE); diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php index c9c05e8..555c198 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php @@ -90,11 +90,11 @@ function testUILanguageNegotiation() { // Setup the site languages by installing two languages. $language = new Language(array( - 'langcode' => $langcode_browser_fallback, + 'id' => $langcode_browser_fallback, )); language_save($language); $language = new Language(array( - 'langcode' => $langcode, + 'id' => $langcode, )); language_save($language); @@ -387,7 +387,7 @@ function testUrlLanguageFallback() { // Add the Italian language. $langcode_browser_fallback = 'it'; $language = new Language(array( - 'langcode' => $langcode_browser_fallback, + 'id' => $langcode_browser_fallback, )); language_save($language); $languages = language_list(); @@ -413,7 +413,7 @@ function testUrlLanguageFallback() { // Access the front page without specifying any valid URL language prefix // and having as browser language preference a non-default language. $http_header = array("Accept-Language: $langcode_browser_fallback;q=1"); - $language = new Language(array('langcode' => '')); + $language = new Language(array('id' => '')); $this->drupalGet('', array('language' => $language), $http_header); // Check that the language switcher active link matches the given browser @@ -434,7 +434,7 @@ function testLanguageDomain() { // Add the Italian language. $langcode = 'it'; $language = new Language(array( - 'langcode' => $langcode, + 'id' => $langcode, )); language_save($language); $languages = language_list(); diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php index 7801959..486c631 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php @@ -56,7 +56,7 @@ function setUp() { function testUrlRewritingEdgeCases() { // Check URL rewriting with a non-installed language. $non_existing = language_default(); - $non_existing->langcode = $this->randomName(); + $non_existing->id = $this->randomName(); $this->checkUrl($non_existing, 'Path language is ignored if language is not installed.', 'URL language negotiation does not work with non-installed languages'); $request = $this->prepareRequestForGenerator(); @@ -90,7 +90,7 @@ private function checkUrl($language, $message1, $message2) { // If the rewritten URL has not a language prefix we pick a random prefix so // we can always check the prefixed URL. $prefixes = language_negotiation_url_prefixes(); - $stored_prefix = isset($prefixes[$language->langcode]) ? $prefixes[$language->langcode] : $this->randomName(); + $stored_prefix = isset($prefixes[$language->id]) ? $prefixes[$language->id] : $this->randomName(); if ($this->assertNotEqual($stored_prefix, $prefix, $message1)) { $prefix = $stored_prefix; } diff --git a/core/modules/language/lib/Drupal/language/Tests/Views/LanguageTestBase.php b/core/modules/language/lib/Drupal/language/Tests/Views/LanguageTestBase.php index 9057a5a..3a8feed 100644 --- a/core/modules/language/lib/Drupal/language/Tests/Views/LanguageTestBase.php +++ b/core/modules/language/lib/Drupal/language/Tests/Views/LanguageTestBase.php @@ -24,14 +24,13 @@ protected function setUp() { parent::setUp(); - $this->installSchema('language', 'language'); $this->installSchema('system', 'variable'); - + $this->installConfig(array('language')); // Create English and another language beside English. - $language = new Language(array('langcode' => 'en')); + $language = new Language(array('id' => 'en')); language_save($language); - $language = new Language(array('langcode' => 'xx-lolspeak', 'name' => 'Lolspeak')); + $language = new Language(array('id' => 'xx-lolspeak', 'name' => 'Lolspeak')); language_save($language); } diff --git a/core/modules/language/tests/language_test/language_test.module b/core/modules/language/tests/language_test/language_test.module index e1fd17d..3cb6f6b 100644 --- a/core/modules/language/tests/language_test/language_test.module +++ b/core/modules/language/tests/language_test/language_test.module @@ -15,7 +15,7 @@ */ function language_test_page_build() { language_test_store_language_negotiation(); - if (isset(language(Language::TYPE_INTERFACE)->langcode) && isset(language(Language::TYPE_INTERFACE)->method_id)) { + if (isset(language(Language::TYPE_INTERFACE)->id) && isset(language(Language::TYPE_INTERFACE)->method_id)) { drupal_set_message(t('Language negotiation method: @name', array('@name' => language(Language::TYPE_INTERFACE)->method_id))); } } @@ -88,7 +88,7 @@ function language_test_language_negotiation_info_alter(array &$negotiation_info) function language_test_store_language_negotiation() { $last = array(); foreach (language_types_get_all() as $type) { - $last[$type] = language($type)->langcode; + $last[$type] = language($type)->id; } Drupal::state()->set('language_test.language_negotiation_last', $last); } diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php index b1aa4b2..7b1219b 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php @@ -125,7 +125,7 @@ public function onKernelRequestSetDefaultConfigContextLocale(GetResponseEvent $e * The localized config name. */ public function getLocaleConfigName($name, Language $language) { - return 'locale.config.' . $language->langcode . '.' . $name; + return 'locale.config.' . $language->id . '.' . $name; } /** diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php index 951fc88..414cde0 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php @@ -53,7 +53,7 @@ function testConfigTranslation() { 'direction' => '0', ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); - $language = new Language(array('langcode' => $langcode)); + $language = new Language(array('id' => $langcode)); // Set path prefix. $edit = array( "prefix[$langcode]" => $langcode ); $this->drupalPost('admin/config/regional/language/detection/url', $edit, t('Save configuration')); diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php index a5ed01b..d7ce9ab 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php @@ -173,7 +173,10 @@ function testPluralEditExport() { // Look up editing page for this plural string and check fields. $path = 'admin/config/regional/translate/'; - $this->drupalGet($path); + $search = array( + 'langcode' => 'hr', + ); + $this->drupalPost($path, $search, t('Filter')); // Labels for plural editing elements. $this->assertText('Singular form'); $this->assertText('First plural form'); diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php index 37b796c..4701645 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php @@ -48,7 +48,7 @@ function setUp() { $this->storage = $this->container->get('locale.storage'); // Create two languages: Spanish and German. foreach (array('es', 'de') as $langcode) { - $language = new Language(array('langcode' => $langcode)); + $language = new Language(array('id' => $langcode)); $languages[$langcode] = language_save($language); } } @@ -180,7 +180,7 @@ function buildSourceString($values = array()) { function createAllTranslations($source, $values = array()) { $list = array(); foreach (language_list() as $language) { - $list[$language->langcode] = $this->createTranslation($source, $language->langcode, $values); + $list[$language->id] = $this->createTranslation($source, $language->id, $values); } return $list; } diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationUiTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationUiTest.php index d2f1579..63ef579 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationUiTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationUiTest.php @@ -480,7 +480,7 @@ function testStringSearch() { function testUICustomizedStrings(){ $user = $this->drupalCreateUser(array('translate interface', 'administer languages', 'access administration pages')); $this->drupalLogin($user); - $language = new Language(array('langcode' => 'de')); + $language = new Language(array('id' => 'de')); language_save($language); // Create test source string diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallFrenchTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallFrenchTest.php index 047ff63..6cd9f3c 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallFrenchTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallFrenchTest.php @@ -26,6 +26,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->langcode = 'fr'; + $this->id = 'fr'; } } diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php index 5675229..c53ed7a 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php @@ -51,7 +51,7 @@ function testUninstallProcess() { $locale_module = array('locale', 'language'); $config = config('locale.settings'); $language = new Language(array( - 'langcode' => 'fr', + 'id' => 'fr', 'name' => 'French', 'default' => $this->langcode == 'fr', )); @@ -68,7 +68,7 @@ function testUninstallProcess() { global $user; $user = drupal_anonymous_user(); - $this->assertEqual(language(Language::TYPE_INTERFACE)->langcode, $this->langcode, t('Current language: %lang', array('%lang' => language(Language::TYPE_INTERFACE)->langcode))); + $this->assertEqual(language(Language::TYPE_INTERFACE)->id, $this->langcode, t('Current language: %lang', array('%lang' => language(Language::TYPE_INTERFACE)->id))); // Enable multilingual workflow option for articles. language_save_default_configuration('node', 'article', array('langcode' => 'site_default', 'language_show' => TRUE)); @@ -115,7 +115,7 @@ function testUninstallProcess() { // Visit the front page. $this->drupalGet(''); // Check the init language logic. - $this->assertEqual(language(Language::TYPE_INTERFACE)->langcode, 'en', t('Language after uninstall: %lang', array('%lang' => language(Language::TYPE_INTERFACE)->langcode))); + $this->assertEqual(language(Language::TYPE_INTERFACE)->id, 'en', t('Language after uninstall: %lang', array('%lang' => language(Language::TYPE_INTERFACE)->id))); // Check JavaScript files deletion. $this->assertTrue($result = !file_exists($js_file), t('JavaScript file deleted: %file', array('%file' => $result ? $js_file : t('found')))); diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index a59c464..0d7520e 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -115,7 +115,7 @@ function locale_translate_import_form_submit($form, &$form_state) { $language = language_load($form_state['values']['langcode']); if (empty($language)) { $language = new Language(array( - 'langcode' => $form_state['values']['langcode'] + 'id' => $form_state['values']['langcode'] )); $language = language_save($language); drupal_set_message(t('The language %language has been created.', array('%language' => t($language->name)))); @@ -171,7 +171,7 @@ function locale_translate_export_form($form, &$form_state) { '#type' => 'select', '#title' => t('Language'), '#options' => $language_options, - '#default_value' => $language_default->langcode, + '#default_value' => $language_default->id, '#empty_option' => t('Source text only, no translations'), '#empty_value' => Language::LANGCODE_SYSTEM, ); @@ -228,11 +228,11 @@ function locale_translate_export_form_submit($form, &$form_state) { $reader = new PoDatabaseReader(); $languageName = ''; if ($language != NULL) { - $reader->setLangcode($language->langcode); + $reader->setLangcode($language->id); $reader->setOptions($content_options); $languages = language_list(); - $languageName = isset($languages[$language->langcode]) ? $languages[$language->langcode]->name : ''; - $filename = $language->langcode .'.po'; + $languageName = isset($languages[$language->id]) ? $languages[$language->id]->name : ''; + $filename = $language->id .'.po'; } else { // Template required. diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 1e605fe..c886940 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -283,7 +283,7 @@ function locale_language_insert($language) { // Changing the language settings impacts the interface. cache('page')->deleteAll(); // Force JavaScript translation file re-creation for the new language. - _locale_invalidate_js($language->langcode); + _locale_invalidate_js($language->id); } /** @@ -294,7 +294,7 @@ function locale_language_update($language) { // Changing the language settings impacts the interface. cache('page')->deleteAll(); // Force JavaScript translation file re-creation for the modified language. - _locale_invalidate_js($language->langcode); + _locale_invalidate_js($language->id); } /** @@ -302,22 +302,22 @@ function locale_language_update($language) { */ function locale_language_delete($language) { // Remove translations. - Drupal::service('locale.storage')->deleteTranslations(array('language' => $language->langcode)); + Drupal::service('locale.storage')->deleteTranslations(array('language' => $language->id)); // Remove interface translation files. module_load_include('inc', 'locale', 'locale.bulk'); - locale_translate_delete_translation_files(array(), array($language->langcode)); + locale_translate_delete_translation_files(array(), array($language->id)); // Remove translated configuration objects. - \Drupal\locale\Locale::config()->deleteLanguageTranslations($language->langcode); + \Drupal\locale\Locale::config()->deleteLanguageTranslations($language->id); // Changing the language settings impacts the interface: - _locale_invalidate_js($language->langcode); + _locale_invalidate_js($language->id); cache('page')->deleteAll(); // Clear locale translation caches. - locale_translation_status_delete_languages(array($language->langcode)); - cache()->delete('locale:' . $language->langcode); + locale_translation_status_delete_languages(array($language->id)); + cache()->delete('locale:' . $language->id); } /** @@ -359,7 +359,7 @@ function locale_get_plural($count, $langcode = NULL) { // individually for each language. $plural_indexes = &drupal_static(__FUNCTION__ . ':plurals', array()); - $langcode = $langcode ? $langcode : $language_interface->langcode; + $langcode = $langcode ? $langcode : $language_interface->id; if (!isset($plural_indexes[$langcode][$count])) { // Retrieve and statically cache the plural formulas for all languages. @@ -629,11 +629,11 @@ function locale_js_alter(&$javascript) { } // If necessary, rebuild the translation file for the current language. - if (!empty($parsed['refresh:' . $language_interface->langcode])) { + if (!empty($parsed['refresh:' . $language_interface->id])) { // Don't clear the refresh flag on failure, so that another try will // be performed later. if (_locale_rebuild_js()) { - unset($parsed['refresh:' . $language_interface->langcode]); + unset($parsed['refresh:' . $language_interface->id]); } // Store any changes after refresh was attempted. Drupal::state()->set('system.javascript_parsed', $parsed); @@ -646,9 +646,9 @@ function locale_js_alter(&$javascript) { // Add the translation JavaScript file to the page. $locale_javascripts = Drupal::state()->get('translation.javascript') ?: array(); - if ($files && !empty($locale_javascripts[$language_interface->langcode])) { + if ($files && !empty($locale_javascripts[$language_interface->id])) { // Add the translation JavaScript file to the page. - $file = $dir . '/' . $language_interface->langcode . '_' . $locale_javascripts[$language_interface->langcode] . '.js'; + $file = $dir . '/' . $language_interface->id . '_' . $locale_javascripts[$language_interface->id] . '.js'; $javascript[$file] = drupal_js_defaults($file); } } @@ -878,7 +878,7 @@ function locale_preprocess_node(&$variables) { $language_interface = language(Language::TYPE_INTERFACE); $node_language = language_load($variables['node']->langcode); - if ($node_language->langcode != $language_interface->langcode) { + if ($node_language->id != $language_interface->id) { // If the node language was different from the page language, we should // add markup to identify the language. Otherwise the page language is // inherited. @@ -1327,7 +1327,7 @@ function _locale_rebuild_js($langcode = NULL) { // Only add strings with a translation to the translations array. $conditions = array( 'type' => 'javascript', - 'language' => $language->langcode, + 'language' => $language->id, 'translated' => TRUE, ); $translations = array(); @@ -1342,8 +1342,8 @@ function _locale_rebuild_js($langcode = NULL) { $data = "Drupal.locale = { "; $locale_plurals = Drupal::state()->get('locale.translation.plurals') ?: array(); - if (!empty($locale_plurals[$language->langcode])) { - $data .= "'pluralFormula': function (\$n) { return Number({$locale_plurals[$language->langcode]['formula']}); }, "; + if (!empty($locale_plurals[$language->id])) { + $data .= "'pluralFormula': function (\$n) { return Number({$locale_plurals[$language->id]['formula']}); }, "; } $data .= "'strings': " . drupal_json_encode($translations) . " };"; @@ -1356,23 +1356,23 @@ function _locale_rebuild_js($langcode = NULL) { // Delete old file, if we have no translations anymore, or a different file to be saved. $locale_javascripts = Drupal::state()->get('locale.translation.javascript') ?: array(); - $changed_hash = !isset($locale_javascripts[$language->langcode]) || ($locale_javascripts[$language->langcode] != $data_hash); - if (!empty($locale_javascripts[$language->langcode]) && (!$data || $changed_hash)) { - file_unmanaged_delete($dir . '/' . $language->langcode . '_' . $locale_javascripts[$language->langcode] . '.js'); - $locale_javascripts[$language->langcode] = ''; + $changed_hash = !isset($locale_javascripts[$language->id]) || ($locale_javascripts[$language->id] != $data_hash); + if (!empty($locale_javascripts[$language->id]) && (!$data || $changed_hash)) { + file_unmanaged_delete($dir . '/' . $language->id . '_' . $locale_javascripts[$language->id] . '.js'); + $locale_javascripts[$language->id] = ''; $status = 'deleted'; } // Only create a new file if the content has changed or the original file got // lost. - $dest = $dir . '/' . $language->langcode . '_' . $data_hash . '.js'; + $dest = $dir . '/' . $language->id . '_' . $data_hash . '.js'; if ($data && ($changed_hash || !file_exists($dest))) { // Ensure that the directory exists and is writable, if possible. file_prepare_directory($dir, FILE_CREATE_DIRECTORY); // Save the file. if (file_unmanaged_save_data($data, $dest)) { - $locale_javascripts[$language->langcode] = $data_hash; + $locale_javascripts[$language->id] = $data_hash; // If we deleted a previous version of the file and we replace it with a // new one we have an update. if ($status == 'deleted') { @@ -1390,7 +1390,7 @@ function _locale_rebuild_js($langcode = NULL) { } } else { - $locale_javascripts[$language->langcode] = ''; + $locale_javascripts[$language->id] = ''; $status = 'error'; } } @@ -1408,7 +1408,7 @@ function _locale_rebuild_js($langcode = NULL) { watchdog('locale', 'Updated JavaScript translation file for the language %language.', array('%language' => $language->name)); return TRUE; case 'rebuilt': - watchdog('locale', 'JavaScript translation file %file.js was lost.', array('%file' => $locale_javascripts[$language->langcode]), WATCHDOG_WARNING); + watchdog('locale', 'JavaScript translation file %file.js was lost.', array('%file' => $locale_javascripts[$language->id]), WATCHDOG_WARNING); // Proceed to the 'created' case as the JavaScript translation file has // been created again. case 'created': diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index eb39f3c..6326905 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -109,7 +109,7 @@ function locale_translate_filters() { } // Pick the current interface language code for the filter. - $default_langcode = language(Language::TYPE_INTERFACE)->langcode; + $default_langcode = language(Language::TYPE_INTERFACE)->id; if (!isset($language_options[$default_langcode])) { $available_langcodes = array_keys($language_options); $default_langcode = array_shift($available_langcodes); diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php index 0a8c245..96ad07f 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php @@ -42,7 +42,7 @@ function setUp() { // Add some custom languages. foreach (array('aa', 'bb', 'cc') as $language_code) { $language = new Language(array( - 'langcode' => $language_code, + 'id' => $language_code, 'name' => $this->randomName(), )); language_save($language); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php index d613cc4..4a6429b 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php @@ -58,11 +58,11 @@ public function setUp() { // Add Hungarian and Catalan. $language = new Language(array( - 'langcode' => 'hu', + 'id' => 'hu', )); language_save($language); $language = new Language(array( - 'langcode' => 'ca', + 'id' => 'ca', )); language_save($language); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareTest.php index be89d79..0fdd4a9 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareTest.php @@ -58,11 +58,11 @@ public function setUp() { // Add Hungarian and Catalan. $language = new Language(array( - 'langcode' => 'hu', + 'id' => 'hu', )); language_save($language); $language = new Language(array( - 'langcode' => 'ca', + 'id' => 'ca', )); language_save($language); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php index 7e7c70a..2a55f16 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php @@ -40,11 +40,11 @@ function setUp() { // Add Hungarian and Catalan. $language = new Language(array( - 'langcode' => 'hu', + 'id' => 'hu', )); language_save($language); $language = new Language(array( - 'langcode' => 'ca', + 'id' => 'ca', )); language_save($language); } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php index e9447ec..cbf3a29 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php @@ -42,7 +42,7 @@ function setUp() { // Add a new language. $language = new Language(array( - 'langcode' => 'it', + 'id' => 'it', 'name' => 'Italian', )); language_save($language); @@ -84,7 +84,7 @@ function testMultilingualNodeForm() { // Check that the node exists in the database. $node = $this->drupalGetNodeByTitle($edit[$title_key])->getNGEntity(); $this->assertTrue($node, 'Node found in database.'); - $this->assertTrue($node->language()->langcode == $langcode && $node->body->value == $body_value, 'Field language correctly set.'); + $this->assertTrue($node->language()->id == $langcode && $node->body->value == $body_value, 'Field language correctly set.'); // Change node language. $langcode = 'it'; @@ -96,7 +96,7 @@ function testMultilingualNodeForm() { $this->drupalPost(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle($edit[$title_key], TRUE)->getNGEntity(); $this->assertTrue($node, 'Node found in database.'); - $this->assertTrue($node->language()->langcode == $langcode && $node->body->value == $body_value, 'Field language correctly changed.'); + $this->assertTrue($node->language()->id == $langcode && $node->body->value == $body_value, 'Field language correctly changed.'); // Enable content language URL detection. language_negotiation_set(Language::TYPE_CONTENT, array(LANGUAGE_NEGOTIATION_URL => 0)); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php index 67cf0b5..a5751eb 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php @@ -59,7 +59,7 @@ function setUp() { // Create revision with a random title and body and update variables. $node->title = $this->randomName(); - $node->body[$node->language()->langcode][0] = array( + $node->body[$node->language()->id][0] = array( 'value' => $this->randomName(32), 'format' => filter_default_format(), ); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php index 640175a..dd2df8d 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php @@ -59,7 +59,7 @@ function setUp() { // Create revision with a random title and body and update variables. $node->title = $this->randomName(); - $node->body[$node->language()->langcode][0] = array( + $node->body[$node->language()->id][0] = array( 'value' => $this->randomName(32), 'format' => filter_default_format(), ); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php index 90b7493..9037751 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php @@ -62,14 +62,14 @@ function testNodeTokenReplacement() { $tests['[node:author]'] = check_plain(user_format_name($account)); $tests['[node:author:uid]'] = $node->uid; $tests['[node:author:name]'] = check_plain(user_format_name($account)); - $tests['[node:created:since]'] = format_interval(REQUEST_TIME - $node->created, 2, $language_interface->langcode); - $tests['[node:changed:since]'] = format_interval(REQUEST_TIME - $node->changed, 2, $language_interface->langcode); + $tests['[node:created:since]'] = format_interval(REQUEST_TIME - $node->created, 2, $language_interface->id); + $tests['[node:changed:since]'] = format_interval(REQUEST_TIME - $node->changed, 2, $language_interface->id); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('node' => $node), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('node' => $node), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced.', array('%token' => $input))); } @@ -81,7 +81,7 @@ function testNodeTokenReplacement() { $tests['[node:author:name]'] = user_format_name($account); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('node' => $node), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('node' => $node), array('langcode' => $language_interface->id, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced.', array('%token' => $input))); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index d01b8ae..1e47081 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -319,7 +319,7 @@ function node_type_get_types() { * An array of node type labels, keyed by the node type name. */ function node_type_get_names() { - $cid = 'node_type:names:' . language(Language::TYPE_INTERFACE)->langcode; + $cid = 'node_type:names:' . language(Language::TYPE_INTERFACE)->id; if ($cache = cache()->get($cid)) { return $cache->data; } @@ -501,6 +501,163 @@ function node_type_update_nodes($old_id, $new_id) { } /** +<<<<<<< HEAD + * Builds and returns the list of available node types. + * + * The list of types is built by invoking hook_node_info() on all modules and + * comparing this information with the node types in the {node_type} table. + * These two information sources are not synchronized during module installation + * until node_types_rebuild() is called. + * + * @param $rebuild + * (optional) TRUE to rebuild node types. Equivalent to calling + * node_types_rebuild(). Defaults to FALSE. + * + * @return + * An object with two properties: + * - names: Associative array of the names of node types, keyed by the type. + * - types: Associative array of node type objects, keyed by the type. + * Both of these arrays will include new types that have been defined by + * hook_node_info() implementations but not yet saved in the {node_type} + * table. These are indicated in the type object by $type->is_new being set + * to the value 1. These arrays will also include obsolete types: types that + * were previously defined by modules that have now been disabled, or for + * whatever reason are no longer being defined in hook_node_info() + * implementations, but are still in the database. These are indicated in the + * type object by $type->disabled being set to TRUE. + */ +function _node_types_build($rebuild = FALSE) { + $cid = 'node_types:' . language(Language::TYPE_INTERFACE)->id; + + if (!$rebuild) { + $_node_types = &drupal_static(__FUNCTION__); + if (isset($_node_types)) { + return $_node_types; + } + if ($cache = cache()->get($cid)) { + $_node_types = $cache->data; + return $_node_types; + } + } + + $_node_types = (object) array('types' => array(), 'names' => array()); + + foreach (module_implements('node_info') as $module) { + $info_array = module_invoke($module, 'node_info'); + foreach ($info_array as $type => $info) { + $info['type'] = $type; + $_node_types->types[$type] = node_type_set_defaults($info); + $_node_types->types[$type]->module = $module; + $_node_types->names[$type] = $info['name']; + } + } + $query = db_select('node_type', 'nt') + ->addTag('node_type_access') + ->fields('nt') + ->orderBy('nt.type', 'ASC'); + if (!$rebuild) { + $query->condition('disabled', 0); + } + foreach ($query->execute() as $type_object) { + $type_db = $type_object->type; + // Original disabled value. + $disabled = $type_object->disabled; + // Check for node types from disabled modules and mark their types for removal. + // Types defined by the node module in the database (rather than by a separate + // module using hook_node_info) have a base value of 'node_content'. The isset() + // check prevents errors on old (pre-Drupal 7) databases. + if (isset($type_object->base) && $type_object->base != 'node_content' && empty($_node_types->types[$type_db])) { + $type_object->disabled = TRUE; + } + if (isset($_node_types->types[$type_db])) { + $type_object->disabled = FALSE; + } + if (!isset($_node_types->types[$type_db]) || $type_object->modified) { + $_node_types->types[$type_db] = $type_object; + $_node_types->names[$type_db] = $type_object->name; + + if ($type_db != $type_object->orig_type) { + unset($_node_types->types[$type_object->orig_type]); + unset($_node_types->names[$type_object->orig_type]); + } + } + $_node_types->types[$type_db]->disabled = $type_object->disabled; + $_node_types->types[$type_db]->disabled_changed = $disabled != $type_object->disabled; + } + + if ($rebuild) { + foreach ($_node_types->types as $type => $type_object) { + if (!empty($type_object->is_new) || !empty($type_object->disabled_changed)) { + node_type_save($type_object); + } + } + } + + asort($_node_types->names); + + cache()->set($cid, $_node_types, CacheBackendInterface::CACHE_PERMANENT, array('node_types' => TRUE)); + + return $_node_types; +} + +/** + * Clears the node type cache. + */ +function node_type_cache_reset() { + cache()->deleteTags(array('node_types' => TRUE)); + drupal_static_reset('_node_types_build'); +} + +/** + * Sets the default values for a node type. + * + * The defaults are appropriate for a type defined through hook_node_info(), + * since 'custom' is TRUE for types defined in the user interface, and FALSE + * for types defined by modules. (The 'custom' flag prevents types from being + * deleted through the user interface.) Also, the default for 'locked' is TRUE, + * which prevents users from changing the machine name of the type. + * + * @param $info + * (optional) An object or array containing values to override the defaults. + * See hook_node_info() for details on what the array elements mean. Defaults + * to an empty array. + * + * @return + * A node type object, with missing values in $info set to their defaults. + * + * @see hook_node_info() + */ +function node_type_set_defaults($info = array()) { + $info = (array) $info; + $new_type = $info + array( + 'type' => '', + 'name' => '', + 'base' => '', + 'description' => '', + 'help' => '', + 'custom' => 0, + 'modified' => 0, + 'locked' => 1, + 'disabled' => 0, + 'is_new' => 1, + 'has_title' => 1, + 'title_label' => 'Title', + ); + $new_type = (object) $new_type; + + // If the type has no title, set an empty label. + if (!$new_type->has_title) { + $new_type->title_label = ''; + } + if (empty($new_type->module)) { + $new_type->module = $new_type->base == 'node_content' ? 'node' : ''; + } + $new_type->orig_type = isset($info['type']) ? $info['type'] : ''; + + return $new_type; +} + +/** * Implements hook_rdf_mapping(). */ function node_rdf_mapping() { @@ -547,7 +704,7 @@ function node_rdf_mapping() { ); } -/**s +/** * Loads node entities from the database. * * This function should be used whenever you need to load more than one node @@ -1010,7 +1167,7 @@ function node_search_execute($keys = NULL, $conditions = NULL) { 'extra' => $extra, 'score' => $item->calculated_score, 'snippet' => search_excerpt($keys, $node->rendered, $item->langcode), - 'langcode' => $node->language()->langcode, + 'langcode' => $node->language()->id, ); } return $results; @@ -1189,7 +1346,7 @@ function _node_revision_access(EntityInterface $node, $op = 'view', $account = N // If no language code was provided, default to the node revision's langcode. if (empty($langcode)) { - $langcode = $node->language()->langcode; + $langcode = $node->language()->id; } // Statically cache access by revision ID, language code, user account ID, @@ -1754,7 +1911,7 @@ function node_feed($nids = FALSE, $channel = array()) { 'title' => config('system.site')->get('name'), 'link' => $base_url, 'description' => $rss_config->get('channel.description'), - 'language' => $language_content->langcode + 'language' => $language_content->id ); $channel_extras = array_diff_key($channel, $channel_defaults); $channel = array_merge($channel_defaults, $channel); @@ -1875,21 +2032,21 @@ function _node_index_node(EntityInterface $node) { foreach ($languages as $language) { // Render the node. - $build = node_view($node, 'search_index', $language->langcode); + $build = node_view($node, 'search_index', $language->id); unset($build['#theme']); $node->rendered = drupal_render($build); - $text = '

' . check_plain($node->label($language->langcode)) . '

' . $node->rendered; + $text = '

' . check_plain($node->label($language->id)) . '

' . $node->rendered; // Fetch extra data normally not visible. - $extra = module_invoke_all('node_update_index', $node, $language->langcode); + $extra = module_invoke_all('node_update_index', $node, $language->id); foreach ($extra as $t) { $text .= $t; } // Update index. - search_index($node->id(), 'node', $text, $language->langcode); + search_index($node->nid, 'node', $text, $language->id); } } @@ -2171,7 +2328,7 @@ function node_access($op, $node, $account = NULL, $langcode = NULL) { // Load languages the node exists in. $node_translations = $node->getTranslationLanguages(); // Load the language from content negotiation. - $content_negotiation_langcode = language(Language::TYPE_CONTENT)->langcode; + $content_negotiation_langcode = language(Language::TYPE_CONTENT)->id; // If there is a translation available, use it. if (isset($node_translations[$content_negotiation_langcode])) { $langcode = $content_negotiation_langcode; @@ -2848,7 +3005,7 @@ function node_language_delete($language) { // On nodes with this language, unset the language. db_update('node') ->fields(array('langcode' => '')) - ->condition('langcode', $language->langcode) + ->condition('langcode', $language->id) ->execute(); } diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 155f595..af8e1e7 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -90,7 +90,7 @@ function node_add($node_type) { 'uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, - 'langcode' => $langcode ? $langcode : language_default()->langcode, + 'langcode' => $langcode ? $langcode : language_default()->id, ))->getBCEntity(); drupal_set_title(t('Create @name', array('@name' => $node_type->name)), PASS_THROUGH); return Drupal::entityManager()->getForm($node); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php index f35b254..266c47d 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php @@ -36,12 +36,12 @@ function setUp() { // Add two new languages. $language = new Language(array( - 'langcode' => 'hu', + 'id' => 'hu', 'name' => 'Hungarian', )); language_save($language); $language = new Language(array( - 'langcode' => 'sv', + 'id' => 'sv', 'name' => 'Swedish', )); language_save($language); diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index 646028a..1ca2b03 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -130,7 +130,7 @@ function template_preprocess_search_result(&$variables) { $result = $variables['result']; $variables['url'] = check_url($result['link']); $variables['title'] = check_plain($result['title']); - if (isset($result['language']) && $result['language'] != $language_interface->langcode && $result['language'] != Language::LANGCODE_NOT_SPECIFIED) { + if (isset($result['language']) && $result['language'] != $language_interface->id && $result['language'] != Language::LANGCODE_NOT_SPECIFIED) { $variables['title_attributes']['lang'] = $result['language']; $variables['content_attributes']['lang'] = $result['language']; } diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php index 7256c30..f13d5cb 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php @@ -56,7 +56,7 @@ function testStatisticsTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = \Drupal::token()->replace($input, array('node' => $node), array('langcode' => $language_interface->langcode)); + $output = \Drupal::token()->replace($input, array('node' => $node), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Statistics token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/system/language.api.php b/core/modules/system/language.api.php index fb165a4..bfcb77f 100644 --- a/core/modules/system/language.api.php +++ b/core/modules/system/language.api.php @@ -27,8 +27,8 @@ function hook_language_switch_links_alter(array &$links, $type, $path) { $language_interface = language(\Drupal\Core\Language\Language::TYPE_INTERFACE); - if ($type == \Drupal\Core\Language\Language::TYPE_CONTENT && isset($links[$language_interface->langcode])) { - foreach ($links[$language_interface->langcode] as $link) { + if ($type == \Drupal\Core\Language\Language::TYPE_CONTENT && isset($links[$language_interface->id])) { + foreach ($links[$language_interface->id] as $link) { $link['attributes']['class'][] = 'active-language'; } } @@ -189,7 +189,7 @@ function hook_language_fallback_candidates_alter(array &$fallback_candidates) { * Here is a code snippet to transliterate some text: * @code * // Use the current default interface language. - * $langcode = language(\Drupal\Core\Language\Language::TYPE_INTERFACE)->langcode; + * $langcode = language(\Drupal\Core\Language\Language::TYPE_INTERFACE)->id; * // Instantiate the transliteration class. * $trans = drupal_container()->get('transliteration'); * // Use this to transliterate some text. diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php index cbce81f..b2efd41 100644 --- a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php +++ b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php @@ -102,7 +102,7 @@ public function buildForm(array $form, array &$form_state, $langcode = NULL, Req * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - $this->configFactory->get('locale.config.' . $this->language->langcode . '.system.date')->delete(); + $this->configFactory->get('locale.config.' . $this->language->id . '.system.date')->delete(); $form_state['redirect'] = 'admin/config/regional/date-time/locale'; } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php index 118a059..af933e4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php @@ -127,8 +127,8 @@ function testFormatDate() { // Save the original user and language and then replace it with the test user and language. $real_user = $user; $user = user_load($test_user->uid, TRUE); - $real_language = $language_interface->langcode; - $language_interface->langcode = $user->preferred_langcode; + $real_language = $language_interface->id; + $language_interface->id = $user->preferred_langcode; // Simulate a Drupal bootstrap with the logged-in user. date_default_timezone_set(drupal_get_user_timezone()); @@ -150,7 +150,7 @@ function testFormatDate() { // Restore the original user and language, and enable session saving. $user = $real_user; - $language_interface->langcode = $real_language; + $language_interface->id = $real_language; // Restore default time zone. date_default_timezone_set(drupal_get_user_timezone()); drupal_save_session(TRUE); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php index d778211..f6a7056 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php @@ -31,7 +31,7 @@ function setUp() { parent::setUp(); $this->installSchema('user', array('users_roles')); $this->installSchema('system', array('variable', 'url_alias')); - $this->installSchema('language', 'language'); + $this->installConfig(array('language')); // Create the default languages. $default_language = language_save(language_default()); @@ -119,7 +119,7 @@ function testEntityTranslationAccess() { // Create two test languages. foreach (array('foo', 'bar') as $langcode) { $language = new Language(array( - 'langcode' => $langcode, + 'id' => $langcode, 'name' => $this->randomString(), )); language_save($language); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index 8e7eea4..e8878be 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -187,14 +187,14 @@ protected function assertReadWrite($entity_type) { $this->assertEqual(language_load(Language::LANGCODE_NOT_SPECIFIED), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type))); // Change the language by code. - $entity->langcode->value = language_default()->langcode; - $this->assertEqual(language_default()->langcode, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); + $entity->langcode->value = language_default()->id; + $this->assertEqual(language_default()->id, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); $this->assertEqual(language_default(), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type))); // Revert language by code then try setting it by language object. $entity->langcode->value = Language::LANGCODE_NOT_SPECIFIED; $entity->langcode->language = language_default(); - $this->assertEqual(language_default()->langcode, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); + $this->assertEqual(language_default()->id, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); $this->assertEqual(language_default(), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type))); // Access the text field and test updating. diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php index cd6fa31..284526f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -56,8 +56,9 @@ public static function getInfo() { function setUp() { parent::setUp(); $this->installSchema('entity_test', array('entity_test_mulrev', 'entity_test_mulrev_property_data', 'entity_test_mulrev_property_revision')); - $this->installSchema('language', array('language')); $this->installSchema('system', array('variable')); + $this->installConfig(array('language')); + $figures = drupal_strtolower($this->randomName()); $greetings = drupal_strtolower($this->randomName()); foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) { @@ -108,17 +109,17 @@ function setUp() { )); // Make these languages available to the greetings field. $langcode = new Language(array( - 'langcode' => 'en', + 'id' => 'en', 'name' => $this->randomString(), )); language_save($langcode); $langcode = new Language(array( - 'langcode' => 'tr', + 'id' => 'tr', 'name' => $this->randomString(), )); language_save($langcode); $langcode = new Language(array( - 'langcode' => 'pl', + 'id' => 'pl', 'name' => $this->randomString(), )); language_save($langcode); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php index 80d00b8..908cb11 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php @@ -41,10 +41,10 @@ function setUp() { $this->langcodes = array(); for ($i = 0; $i < 2; ++$i) { $language = new Language(array( - 'langcode' => 'l' . $i, + 'id' => 'l' . $i, 'name' => $this->randomString(), )); - $this->langcodes[$i] = $language->langcode; + $this->langcodes[$i] = $language->id; language_save($language); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php index a235add..e0c3189 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -31,7 +31,6 @@ public static function getInfo() { function setUp() { parent::setUp(); $this->installSchema('system', 'variable'); - $this->installSchema('language', 'language'); $this->installSchema('entity_test', array( 'entity_test_mul', 'entity_test_mul_property_data', @@ -41,6 +40,7 @@ function setUp() { 'entity_test_mulrev_property_data', 'entity_test_mulrev_property_revision', )); + $this->installConfig(array('language')); // Create the test field. entity_test_install(); @@ -79,10 +79,10 @@ function setUp() { $this->langcodes = array(); for ($i = 0; $i < 3; ++$i) { $language = new Language(array( - 'langcode' => 'l' . $i, + 'id' => 'l' . $i, 'name' => $this->randomString(), )); - $this->langcodes[$i] = $language->langcode; + $this->langcodes[$i] = $language->id; language_save($language); } } @@ -108,7 +108,7 @@ protected function assertEntityLanguageMethods($entity_type) { 'name' => 'test', 'user_id' => $GLOBALS['user']->uid, )); - $this->assertEqual($entity->language()->langcode, Language::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', array('%entity_type' => $entity_type))); + $this->assertEqual($entity->language()->id, Language::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', array('%entity_type' => $entity_type))); $this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type))); // Set the value in default language. @@ -227,7 +227,7 @@ protected function assertMultilingualProperties($entity_type) { $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid)); $entity->save(); $entity = entity_load($entity_type, $entity->id()); - $this->assertEqual($entity->language()->langcode, Language::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity created as language neutral.', array('%entity_type' => $entity_type))); + $this->assertEqual($entity->language()->id, Language::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity created as language neutral.', array('%entity_type' => $entity_type))); $this->assertEqual($name, $entity->getTranslation(Language::LANGCODE_DEFAULT)->get('name')->value, format_string('%entity_type: The entity name has been correctly stored as language neutral.', array('%entity_type' => $entity_type))); $this->assertEqual($uid, $entity->getTranslation(Language::LANGCODE_DEFAULT)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored as language neutral.', array('%entity_type' => $entity_type))); // As fields, translatable properties should ignore the given langcode and @@ -242,7 +242,7 @@ protected function assertMultilingualProperties($entity_type) { $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid, 'langcode' => $langcode)); $entity->save(); $entity = entity_load($entity_type, $entity->id()); - $this->assertEqual($entity->language()->langcode, $langcode, format_string('%entity_type: Entity created as language specific.', array('%entity_type' => $entity_type))); + $this->assertEqual($entity->language()->id, $langcode, format_string('%entity_type: Entity created as language specific.', array('%entity_type' => $entity_type))); $this->assertEqual($name, $entity->getTranslation($langcode)->get('name')->value, format_string('%entity_type: The entity name has been correctly stored as a language-aware property.', array('%entity_type' => $entity_type))); $this->assertEqual($uid, $entity->getTranslation($langcode)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored as a language-aware property.', array('%entity_type' => $entity_type))); // Translatable properties on a translatable entity should use default diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/LanguageSelectElementTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/LanguageSelectElementTest.php index 09044e6..2705aed 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/LanguageSelectElementTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/LanguageSelectElementTest.php @@ -36,13 +36,13 @@ public static function getInfo() { function testLanguageSelectElementOptions() { // Add some languages. $language = new Language(array( - 'langcode' => 'aaa', + 'id' => 'aaa', 'name' => $this->randomName(), )); language_save($language); $language = new Language(array( - 'langcode' => 'bbb', + 'id' => 'bbb', 'name' => $this->randomName(), )); language_save($language); diff --git a/core/modules/system/lib/Drupal/system/Tests/Mail/MailTest.php b/core/modules/system/lib/Drupal/system/Tests/Mail/MailTest.php index 3dad764..d832f06 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Mail/MailTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Mail/MailTest.php @@ -53,7 +53,7 @@ public function testPluggableFramework() { $language_interface = language(Language::TYPE_INTERFACE); // Use MailTestCase for sending a message. - $message = drupal_mail('simpletest', 'mail_test', 'testing@example.com', $language_interface->langcode); + $message = drupal_mail('simpletest', 'mail_test', 'testing@example.com', $language_interface->id); // Assert whether the message was sent through the send function. $this->assertEqual(self::$sent_message['to'], 'testing@example.com', 'Pluggable mail system is extendable.'); @@ -71,7 +71,7 @@ public function testCancelMessage() { self::$sent_message = NULL; // Send a test message that simpletest_mail_alter should cancel. - $message = drupal_mail('simpletest', 'cancel_test', 'cancel@example.com', $language_interface->langcode); + $message = drupal_mail('simpletest', 'cancel_test', 'cancel@example.com', $language_interface->id); // Assert that the message was not actually sent. $this->assertNull(self::$sent_message, 'Message was canceled.'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php index 0143d1a..6b3383b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php @@ -39,8 +39,9 @@ function testEnableWithoutDependency() { $this->assertModules(array('content_translation', 'language'), TRUE); - // Assert that the language tables were enabled. - $this->assertTableCount('language', TRUE); + // Assert that the language YAML files were created. + $storage = $this->container->get('config.storage'); + $this->assertTrue(count($storage->listAll('language.entity.')) > 0, 'Language config entity files exist.'); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorLanguageTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorLanguageTest.php index 23d01fa..1afeca5 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorLanguageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorLanguageTest.php @@ -61,7 +61,7 @@ public function setUp() { // Create two languages: Spanish and German. $this->languages = array('de', 'es'); foreach ($this->languages as $langcode) { - $language = new Language(array('langcode' => $langcode)); + $language = new Language(array('id' => $langcode)); $languages[$langcode] = language_save($language); // Set up translations for each mock block label. $custom_strings = array(); diff --git a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php index d32f297..a220835 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php @@ -45,18 +45,18 @@ function testTokenReplacement() { $target = check_plain($node->title); $target .= check_plain($account->name); - $target .= format_interval(REQUEST_TIME - $node->created, 2, $language_interface->langcode); + $target .= format_interval(REQUEST_TIME - $node->created, 2, $language_interface->id); $target .= check_plain($user->name); - $target .= format_date(REQUEST_TIME, 'short', '', NULL, $language_interface->langcode); + $target .= format_date(REQUEST_TIME, 'short', '', NULL, $language_interface->id); // Test that the clear parameter cleans out non-existent tokens. - $result = $token_service->replace($source, array('node' => $node), array('langcode' => $language_interface->langcode, 'clear' => TRUE)); + $result = $token_service->replace($source, array('node' => $node), array('langcode' => $language_interface->id, 'clear' => TRUE)); $result = $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens cleared out.'); // Test without using the clear parameter (non-existent token untouched). $target .= '[user:name]'; $target .= '[bogus:token]'; - $result = $token_service->replace($source, array('node' => $node), array('langcode' => $language_interface->langcode)); + $result = $token_service->replace($source, array('node' => $node), array('langcode' => $language_interface->id)); $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.'); // Check that the results of Token::generate are sanitized properly. This @@ -99,7 +99,7 @@ function testSystemTokenRecognition() { foreach ($tests as $test) { $input = $test['prefix'] . '[site:name]' . $test['suffix']; $expected = $test['prefix'] . 'Drupal' . $test['suffix']; - $output = $token_service->replace($input, array(), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array(), array('langcode' => $language_interface->id)); $this->assertTrue($output == $expected, format_string('Token recognized in string %string', array('%string' => $input))); } } @@ -134,7 +134,7 @@ function testSystemSiteTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array(), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array(), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Sanitized system site information token %token replaced.', array('%token' => $input))); } @@ -143,7 +143,7 @@ function testSystemSiteTokenReplacement() { $tests['[site:slogan]'] = config('system.site')->get('slogan'); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array(), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array(), array('langcode' => $language_interface->id, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized system site information token %token replaced.', array('%token' => $input))); } } @@ -160,18 +160,18 @@ function testSystemDateTokenReplacement() { // Generate and test tokens. $tests = array(); - $tests['[date:short]'] = format_date($date, 'short', '', NULL, $language_interface->langcode); - $tests['[date:medium]'] = format_date($date, 'medium', '', NULL, $language_interface->langcode); - $tests['[date:long]'] = format_date($date, 'long', '', NULL, $language_interface->langcode); - $tests['[date:custom:m/j/Y]'] = format_date($date, 'custom', 'm/j/Y', NULL, $language_interface->langcode); - $tests['[date:since]'] = format_interval((REQUEST_TIME - $date), 2, $language_interface->langcode); + $tests['[date:short]'] = format_date($date, 'short', '', NULL, $language_interface->id); + $tests['[date:medium]'] = format_date($date, 'medium', '', NULL, $language_interface->id); + $tests['[date:long]'] = format_date($date, 'long', '', NULL, $language_interface->id); + $tests['[date:custom:m/j/Y]'] = format_date($date, 'custom', 'm/j/Y', NULL, $language_interface->id); + $tests['[date:since]'] = format_interval((REQUEST_TIME - $date), 2, $language_interface->id); $tests['[date:raw]'] = filter_xss($date); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('date' => $date), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('date' => $date), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Date token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php index 506ec4c..86433d1 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -42,11 +42,26 @@ public function testLanguageUpgrade() { db_update('users')->fields(array('language' => 'ca'))->condition('uid', '1')->execute(); $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + // Check that the configuration for the 'Catalan' language is correct. + $config = $this->container->get('config.factory')->get('language.entity.ca')->get(); + // We cannot predict the value of the UUID, we just check it's present. + $this->assertFalse(empty($config['uuid'])); + unset($config['uuid']); + $this->assertEqual($config, array( + 'id' => 'ca', + 'label' => 'Catalan', + 'direction' => 0, + 'weight' => 0, + 'locked' => 0, + 'status' => 1, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, + )); + // Ensure Catalan was properly upgraded to be the new default language. - $this->assertTrue(language_default()->langcode == 'ca', 'Catalan is the default language'); + $this->assertTrue(language_default()->id == 'ca', 'Catalan is the default language'); $languages = language_list(Language::STATE_ALL); foreach ($languages as $language) { - $this->assertTrue($language->default == ($language->langcode == 'ca'), format_string('@language default property properly set', array('@language' => $language->name))); + $this->assertTrue($language->default == ($language->id == 'ca'), format_string('@language default property properly set', array('@language' => $language->name))); } // Check that both comments display on the node. diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 16bb0de..14ac01a 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1856,7 +1856,7 @@ function hook_watchdog(array $log_entry) { '@message' => strip_tags($log_entry['message']), )); - drupal_mail('emaillog', 'entry', $to, $language_interface->langcode, $params); + drupal_mail('emaillog', 'entry', $to, $language_interface->id, $params); } /** diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php index 0ad1da0..a05d00b 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php @@ -47,7 +47,7 @@ public function form(array $form, array &$form_state) { $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', - '#default_value' => $entity->language()->langcode, + '#default_value' => $entity->language()->id, '#languages' => Language::STATE_ALL, ); diff --git a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/CachedMockBlockManager.php b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/CachedMockBlockManager.php index 139a01f..cc5b516 100644 --- a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/CachedMockBlockManager.php +++ b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/CachedMockBlockManager.php @@ -25,6 +25,6 @@ public function __construct() { // The CacheDecorator allows us to cache these plugin definitions for // quicker retrieval. In this case we are generating a cache key by // language. - $this->discovery = new CacheDecorator($this->discovery, 'mock_block:' . language(Language::TYPE_INTERFACE)->langcode, 'cache', 1542646800, array('plugin_test')); + $this->discovery = new CacheDecorator($this->discovery, 'mock_block:' . language(Language::TYPE_INTERFACE)->id, 'cache', 1542646800, array('plugin_test')); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php index b54b753..ba53d03 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php @@ -37,7 +37,7 @@ function setUp() { // Add some custom languages. foreach (array('aa', 'bb', 'cc') as $language_code) { $language = new Language(array( - 'langcode' => $language_code, + 'id' => $language_code, 'name' => $this->randomName(), )); language_save($language); @@ -63,7 +63,7 @@ function testTermLanguage() { $this->drupalPost(NULL, $edit, t('Save')); $terms = taxonomy_term_load_multiple_by_name($edit['name']); $term = reset($terms); - $this->assertEqual($term->language()->langcode, $edit['langcode']); + $this->assertEqual($term->language()->id, $edit['langcode']); // Check if on the edit page the language is correct. $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php index eec5921..622eae7 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php @@ -94,7 +94,7 @@ function testTaxonomyTokenReplacement() { $tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input))); } @@ -114,7 +114,7 @@ function testTaxonomyTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input))); } @@ -125,7 +125,7 @@ function testTaxonomyTokenReplacement() { $tests['[term:vocabulary:name]'] = $this->vocabulary->name; foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->id, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy term token %token replaced.', array('%token' => $input))); } @@ -141,7 +141,7 @@ function testTaxonomyTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', array('%token' => $input))); } @@ -150,7 +150,7 @@ function testTaxonomyTokenReplacement() { $tests['[vocabulary:description]'] = $this->vocabulary->description; foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->id, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy vocabulary token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php index 14c915c..cb4a2a8 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php @@ -33,13 +33,13 @@ function setUp() { // Add some custom languages. $language = new Language(array( - 'langcode' => 'aa', + 'id' => 'aa', 'name' => $this->randomName(), )); language_save($language); $language = new Language(array( - 'langcode' => 'bb', + 'id' => 'bb', 'name' => $this->randomName(), )); language_save($language); diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index e8bd8e0..7db05ef 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -15,7 +15,7 @@ function taxonomy_vocabulary_add() { $vocabulary = entity_create('taxonomy_vocabulary', array( // Default the new vocabulary to the site's default language. This is the // most likely default value until we have better flexible settings. - 'langcode' => language_default()->langcode, + 'langcode' => language_default()->id, )); return Drupal::entityManager()->getForm($vocabulary); } diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index f579755..860cde3 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -247,7 +247,7 @@ function taxonomy_update_8001() { // When updating from a site that did not already have taxonomy // internationalization, initialize all existing vocabularies and terms as // being in the site's default language. - $langcode_field['initial'] = language_default()->langcode; + $langcode_field['initial'] = language_default()->id; db_add_field($table, 'langcode', $langcode_field); } } diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php index 17f2ba3..80c93b3 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php @@ -98,7 +98,7 @@ public function prepareCache() { // field in the filter cache separately. if (!$this->getInstance()->settings['text_processing'] || filter_format_allowcache($this->get('format')->getValue())) { $itemBC = $this->getValue(); - $langcode = $this->getParent()->getParent()->language()->langcode; + $langcode = $this->getParent()->getParent()->language()->id; $this->set('safe_value', text_sanitize($this->getInstance()->settings['text_processing'], $langcode, $itemBC, 'value')); if ($this->getType() == 'field_item:text_with_summary') { $this->set('safe_summary', text_sanitize($this->getInstance()->settings['text_processing'], $langcode, $itemBC, 'summary')); diff --git a/core/modules/text/lib/Drupal/text/TextProcessed.php b/core/modules/text/lib/Drupal/text/TextProcessed.php index 2b5cb65..9a1910f 100644 --- a/core/modules/text/lib/Drupal/text/TextProcessed.php +++ b/core/modules/text/lib/Drupal/text/TextProcessed.php @@ -70,7 +70,7 @@ public function getValue($langcode = NULL) { $instance = field_info_instance($entity->entityType(), $field->getName(), $entity->bundle()); if (!empty($instance['settings']['text_processing']) && $this->format->getValue()) { - return check_markup($this->text->getValue(), $this->format->getValue(), $entity->language()->langcode); + return check_markup($this->text->getValue(), $this->format->getValue(), $entity->language()->id); } else { // If no format is available, still make sure to sanitize the text. diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 14135bb..51b7d25 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -632,7 +632,7 @@ function toolbar_library_info() { */ function _toolbar_get_subtree_hash() { global $user; - $cid = $user->uid . ':' . language(Language::TYPE_INTERFACE)->langcode; + $cid = $user->uid . ':' . language(Language::TYPE_INTERFACE)->id; if ($cache = cache('toolbar')->get($cid)) { $hash = $cache->data; } diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php index db69e18..dcadd3f 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php @@ -88,7 +88,7 @@ public function testTourFunctionality() { // Enable Italian language and navigate to it/tour-test1 and verify italian // version of tip is found. - language_save(new Language(array('langcode' => 'it'))); + language_save(new Language(array('id' => 'it'))); $this->drupalGet('it/tour-test-1'); $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( @@ -103,7 +103,7 @@ public function testTourFunctionality() { )); $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.'); - language_save(new Language(array('langcode' => 'en'))); + language_save(new Language(array('id' => 'en'))); // Programmatically create a tour for use through the remainder of the test. entity_create('tour', array( diff --git a/core/modules/update/update.fetch.inc b/core/modules/update/update.fetch.inc index 13a1383..2d03d49 100644 --- a/core/modules/update/update.fetch.inc +++ b/core/modules/update/update.fetch.inc @@ -352,7 +352,7 @@ function _update_cron_notify() { if (!empty($params)) { $notify_list = $update_config->get('notification.emails'); if (!empty($notify_list)) { - $default_langcode = language_default()->langcode; + $default_langcode = language_default()->id; foreach ($notify_list as $target) { if ($target_user = user_load_by_mail($target)) { $target_langcode = user_preferred_langcode($target_user); diff --git a/core/modules/user/lib/Drupal/user/AccountFormController.php b/core/modules/user/lib/Drupal/user/AccountFormController.php index 13ad217..6505d29 100644 --- a/core/modules/user/lib/Drupal/user/AccountFormController.php +++ b/core/modules/user/lib/Drupal/user/AccountFormController.php @@ -176,9 +176,9 @@ public function form(array $form, array &$form_state) { '#format' => isset($account->signature_format) ? $account->signature_format : NULL, ); - $user_preferred_langcode = $register ? $language_interface->langcode : user_preferred_langcode($account); + $user_preferred_langcode = $register ? $language_interface->id : user_preferred_langcode($account); - $user_preferred_admin_langcode = $register ? $language_interface->langcode : user_preferred_langcode($account, 'admin'); + $user_preferred_admin_langcode = $register ? $language_interface->id : user_preferred_langcode($account, 'admin'); // Is default the interface language? include_once DRUPAL_ROOT . '/core/includes/language.inc'; diff --git a/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php b/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php index 47fc23b..185a16f 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php @@ -129,7 +129,7 @@ public function validateForm(array &$form, array &$form_state) { * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - $langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->langcode; + $langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id; $account = $form_state['values']['account']; // Mail one time login URL and instructions using current language. diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php index da27a0e..32dc5cc 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php @@ -185,8 +185,8 @@ function testRegistrationDefaultValues() { $this->assertTrue(($new_user->created->value > REQUEST_TIME - 20 ), 'Correct creation time.'); $this->assertEqual($new_user->status->value, $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.'); $this->assertEqual($new_user->timezone->value, $config_system_timezone->get('default'), 'Correct time zone field.'); - $this->assertEqual($new_user->langcode->value, language_default()->langcode, 'Correct language field.'); - $this->assertEqual($new_user->preferred_langcode->value, language_default()->langcode, 'Correct preferred language field.'); + $this->assertEqual($new_user->langcode->value, language_default()->id, 'Correct language field.'); + $this->assertEqual($new_user->preferred_langcode->value, language_default()->id, 'Correct preferred language field.'); $this->assertEqual($new_user->init->value, $mail, 'Correct init field.'); } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php index 43b9827..1493829 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php @@ -32,7 +32,7 @@ function setUp() { */ function testRoleAdministration() { $this->drupalLogin($this->admin_user); - $default_langcode = language_default()->langcode; + $default_langcode = language_default()->id; // Test adding a role. (In doing so, we use a role name that happens to // correspond to an integer, to test that the role administration pages diff --git a/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php b/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php index 71d4a78..347f3d0 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php @@ -33,7 +33,7 @@ public static function getInfo() { public function setUp() { parent::setUp(); $language = new Language(array( - 'langcode' => 'de', + 'id' => 'de', )); language_save($language); } @@ -66,17 +66,17 @@ function testUserTokenReplacement() { $tests['[user:mail]'] = check_plain($account->mail); $tests['[user:url]'] = url("user/$account->uid", $url_options); $tests['[user:edit-url]'] = url("user/$account->uid/edit", $url_options); - $tests['[user:last-login]'] = format_date($account->login, 'medium', '', NULL, $language_interface->langcode); - $tests['[user:last-login:short]'] = format_date($account->login, 'short', '', NULL, $language_interface->langcode); - $tests['[user:created]'] = format_date($account->created, 'medium', '', NULL, $language_interface->langcode); - $tests['[user:created:short]'] = format_date($account->created, 'short', '', NULL, $language_interface->langcode); + $tests['[user:last-login]'] = format_date($account->login, 'medium', '', NULL, $language_interface->id); + $tests['[user:last-login:short]'] = format_date($account->login, 'short', '', NULL, $language_interface->id); + $tests['[user:created]'] = format_date($account->created, 'medium', '', NULL, $language_interface->id); + $tests['[user:created:short]'] = format_date($account->created, 'short', '', NULL, $language_interface->id); $tests['[current-user:name]'] = check_plain(user_format_name($global_account)); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->langcode)); + $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->id)); $this->assertEqual($output, $expected, format_string('Sanitized user token %token replaced.', array('%token' => $input))); } @@ -86,7 +86,7 @@ function testUserTokenReplacement() { $tests['[current-user:name]'] = user_format_name($global_account); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->id, 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized user token %token replaced.', array('%token' => $input))); } @@ -98,7 +98,7 @@ function testUserTokenReplacement() { // Generate tokens with interface language. $link = url('user', array('absolute' => TRUE)); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->langcode, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); + $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->id, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); $this->assertTrue(strpos($output, $link) === 0, 'Generated URL is in interface language.'); } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index eb6b4f3..901240d 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1948,10 +1948,10 @@ function user_preferred_langcode($account, $type = NULL, $default = NULL) { $preferred_langcode = $account->preferred_langcode; } if (!empty($preferred_langcode) && isset($language_list[$preferred_langcode])) { - return $language_list[$preferred_langcode]->langcode; + return $language_list[$preferred_langcode]->id; } else { - return $default ? $default : language_default()->langcode; + return $default ? $default : language_default()->id; } } @@ -2007,7 +2007,7 @@ function _user_mail_notify($op, $account, $langcode = NULL) { if ($op == 'register_pending_approval') { // If a user registered requiring admin approval, notify the admin, too. // We use the site default language for this. - drupal_mail('user', 'register_pending_approval_admin', $site_mail, language_default()->langcode, $params); + drupal_mail('user', 'register_pending_approval_admin', $site_mail, language_default()->id, $params); } } return empty($mail) ? NULL : $mail['result']; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php index 2b7fa9c..62ed735 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php @@ -287,7 +287,7 @@ public function generateResultsKey() { 'build_info' => $build_info, 'roles' => $user->roles, 'super-user' => $user->uid == 1, // special caching for super user. - 'langcode' => language(Language::TYPE_INTERFACE)->langcode, + 'langcode' => language(Language::TYPE_INTERFACE)->id, 'base_url' => $GLOBALS['base_url'], ); $request = \Drupal::request(); @@ -317,7 +317,7 @@ public function generateOutputKey() { 'roles' => $user->roles, 'super-user' => $user->uid == 1, // special caching for super user. 'theme' => $GLOBALS['theme'], - 'langcode' => language(Language::TYPE_INTERFACE)->langcode, + 'langcode' => language(Language::TYPE_INTERFACE)->id, 'base_url' => $GLOBALS['base_url'], ); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php index 50a8215..cd56c28 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php @@ -624,7 +624,7 @@ protected function instantiateView($form, &$form_state) { 'label' => $form_state['values']['label'], 'description' => $form_state['values']['description'], 'base_table' => $this->base_table, - 'langcode' => language_default()->langcode, + 'langcode' => language_default()->id, ); $view = entity_create('view', $values); diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php index b191e9a..8d2fad6 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php @@ -43,8 +43,8 @@ public static function getInfo() { protected function setUp() { parent::setUp(); - $this->installSchema('language', 'language'); $this->installSchema('system', 'variable'); + $this->installConfig(array('language')); $this->enableModules(array('views_ui')); @@ -66,7 +66,7 @@ public function testCreateView() { // Add a new language and mark it as default. $language = new Language(array( - 'langcode' => 'it', + 'id' => 'it', 'name' => 'Italian', 'default' => TRUE, )); diff --git a/core/modules/views/lib/Drupal/views/ViewsData.php b/core/modules/views/lib/Drupal/views/ViewsData.php index 2a1c2b2..427006b 100644 --- a/core/modules/views/lib/Drupal/views/ViewsData.php +++ b/core/modules/views/lib/Drupal/views/ViewsData.php @@ -96,7 +96,7 @@ public function __construct(CacheBackendInterface $cache_backend, ConfigFactory $this->moduleHandler = $module_handler; $this->languageManager = $language_manager; - $this->langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->langcode; + $this->langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id; $this->skipCache = $config->get('views.settings')->get('skip_cache'); } diff --git a/core/modules/views/views.api.php b/core/modules/views/views.api.php index 3001caa..d57e28e 100644 --- a/core/modules/views/views.api.php +++ b/core/modules/views/views.api.php @@ -338,8 +338,8 @@ function hook_views_query_substitutions(ViewExecutable $view) { return array( '***CURRENT_VERSION***' => VERSION, '***CURRENT_TIME***' => REQUEST_TIME, - '***CURRENT_LANGUAGE***' => language(\Drupal\Core\Language\Language::TYPE_CONTENT)->langcode, - '***DEFAULT_LANGUAGE***' => language_default()->langcode, + '***CURRENT_LANGUAGE***' => language(\Drupal\Core\Language\Language::TYPE_CONTENT)->id, + '***DEFAULT_LANGUAGE***' => language_default()->id, ); } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index d48526f..4dedbe1 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -641,7 +641,7 @@ function views_language_list($field = 'name', $flags = Language::STATE_ALL) { $languages = language_list($flags); $list = array(); foreach ($languages as $language) { - $list[$language->langcode] = ($field == 'name') ? t($language->name) : $language->$field; + $list[$language->id] = ($field == 'name') ? t($language->name) : $language->$field; } return $list; } @@ -1627,7 +1627,7 @@ function views_cache_set($cid, $data, $use_language = FALSE) { return; } if ($use_language) { - $cid .= ':' . language(Language::TYPE_INTERFACE)->langcode; + $cid .= ':' . language(Language::TYPE_INTERFACE)->id; } cache('views_info')->set($cid, $data); @@ -1651,7 +1651,7 @@ function views_cache_get($cid, $use_language = FALSE) { return FALSE; } if ($use_language) { - $cid .= ':' . language(Language::TYPE_INTERFACE)->langcode; + $cid .= ':' . language(Language::TYPE_INTERFACE)->id; } return cache('views_info')->get($cid); diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 237a91e..aceae1f 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -993,7 +993,7 @@ function template_preprocess_views_view_rss(&$vars) { $vars['link'] = check_url(url($path, $url_options)); } - $vars['langcode'] = check_plain(language(Language::TYPE_INTERFACE)->langcode); + $vars['langcode'] = check_plain(language(Language::TYPE_INTERFACE)->id); $vars['namespaces'] = new Attribute($style->namespaces); $vars['items'] = $items; $vars['channel_elements'] = format_xml_elements($style->channel_elements); diff --git a/core/modules/views/views.tokens.inc b/core/modules/views/views.tokens.inc index fc119b8..ae307fd 100644 --- a/core/modules/views/views.tokens.inc +++ b/core/modules/views/views.tokens.inc @@ -74,7 +74,7 @@ function views_tokens($type, $tokens, array $data = array(), array $options = ar $url_options['language'] = $options['language']; } $sanitize = !empty($options['sanitize']); - $langcode = isset($options['language']) ? $options['language']->langcode : NULL; + $langcode = isset($options['language']) ? $options['language']->id : NULL; $replacements = array(); diff --git a/core/modules/views/views.views_execution.inc b/core/modules/views/views.views_execution.inc index 5b0966a..ddde9d9 100644 --- a/core/modules/views/views.views_execution.inc +++ b/core/modules/views/views.views_execution.inc @@ -17,7 +17,7 @@ function views_views_query_substitutions(ViewExecutable $view) { return array( '***CURRENT_VERSION***' => VERSION, '***CURRENT_TIME***' => REQUEST_TIME, - '***CURRENT_LANGUAGE***' => language(Language::TYPE_CONTENT)->langcode, - '***DEFAULT_LANGUAGE***' => language_default()->langcode, + '***CURRENT_LANGUAGE***' => language(Language::TYPE_CONTENT)->id, + '***DEFAULT_LANGUAGE***' => language_default()->id, ); } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/StorageTest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/StorageTest.php index 0f32d96..24582db 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Tests/StorageTest.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/StorageTest.php @@ -44,7 +44,7 @@ public static function getInfo() { public function testDetails() { $view_name = 'test_view'; - $language = new Language(array('name' => 'French', 'langcode' => 'fr')); + $language = new Language(array('name' => 'French', 'id' => 'fr')); language_save($language); $edit = array( diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php index fdbcee6..f49184f 100644 --- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php @@ -39,7 +39,7 @@ public function setUp() { $languages = array(); foreach (array('en' => 'English', 'fr' => 'French') as $langcode => $language_name) { $language = new \stdClass(); - $language->langcode = $langcode; + $language->id = $langcode; $language->name = $language_name; $languages[$langcode] = $language; } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 67ee7d5..bd6ba26 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -112,7 +112,7 @@ public function testDefaultPluginManagerWithEmptyCache() { ->method('set') ->with($cid . ':en', $this->expectedDefinitions); - $language = new Language(array('langcode' => 'en')); + $language = new Language(array('id' => 'en')); $language_manager = $this->getMock('Drupal\Core\Language\LanguageManager'); $language_manager->expects($this->once()) ->method('getLanguage') @@ -143,7 +143,7 @@ public function testDefaultPluginManagerWithFilledCache() { ->expects($this->never()) ->method('set'); - $language = new Language(array('langcode' => 'en')); + $language = new Language(array('id' => 'en')); $language_manager = $this->getMock('Drupal\Core\Language\LanguageManager'); $language_manager->expects($this->once()) ->method('getLanguage')