Commit 4c357934 authored by alexpott's avatar alexpott

Issue #1754246 by webflo, swentel, penyaskito, andypost, alexpott, YesCT,...

Issue #1754246 by webflo, swentel, penyaskito, andypost, alexpott, YesCT, dagmar: Languages should be configuration entities.
parent 0c957d31
......@@ -2395,7 +2395,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);
}
/**
......@@ -2476,18 +2476,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);
}
......@@ -2535,12 +2544,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,7 +2615,7 @@ function language_is_locked($langcode) {
*/
function language_default() {
$info = variable_get('language_default', array(
'langcode' => 'en',
'id' => 'en',
'name' => 'English',
'direction' => 0,
'weight' => 0,
......
......@@ -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 = "<channel>\n";
$output .= ' <title>' . check_plain($title) . "</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 == '<front>' && $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;
}
}
......
......@@ -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;
}
......
......@@ -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');
......
......@@ -298,8 +298,14 @@ 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']) {
$GLOBALS['conf']['language_default'] = array('langcode' => $install_state['parameters']['langcode']);
// The language list is stored in configuration and cannot be saved either
// until later in the process. Language negotiation bootstrapping needs
// the new default language to be in the list though, so inject it in.
if (!empty($install_state['parameters']['langcode']) && language_default()->id != $install_state['parameters']['langcode']) {
$GLOBALS['conf']['language_default'] = array('id' => $install_state['parameters']['langcode']);
$languages = &drupal_static('language_list');
$languages[$install_state['parameters']['langcode']] = new Language($GLOBALS['conf']['language_default']);
}
require_once __DIR__ . '/../modules/system/system.install';
......@@ -1547,7 +1553,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 +1562,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 +1825,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 +1834,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 +2503,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')
......
......@@ -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));
}
......
......@@ -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])) {
......
......@@ -1731,7 +1731,7 @@ function theme_links($variables) {
// Handle links.
if (isset($link['href'])) {
$is_current_path = ($link['href'] == current_path() || ($link['href'] == '<front>' && 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.
......
......@@ -319,9 +319,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,
......@@ -534,7 +534,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.
......@@ -548,14 +548,31 @@ 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);
// In D8, the 'language_default' is not anymore an object, but an array,
// so make sure that the new value that is saved into this variable is an
// array.
variable_set('language_default', (array) $language_default);
$language_default = (array) $language_default;
$language_default['langcode'] = 'en';
variable_set('language_default', $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.
......@@ -1572,3 +1589,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;
}
......@@ -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
......
......@@ -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.
......
......@@ -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.
......
......@@ -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);
......
......@@ -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;
......
......@@ -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]);
}
......
......@@ -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'];
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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.
......