diff -u b/core/lib/Drupal/Core/Language/Language.php b/core/lib/Drupal/Core/Language/Language.php --- b/core/lib/Drupal/Core/Language/Language.php +++ b/core/lib/Drupal/Core/Language/Language.php @@ -210,6 +210,13 @@ } /** + * {@inheritdoc} + */ + public function isLocked() { + return $this->locked; + } + + /** * Sort language objects. * * @param array $languages diff -u b/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc --- b/core/modules/content_translation/content_translation.pages.inc +++ b/core/modules/content_translation/content_translation.pages.inc @@ -45,8 +45,8 @@ } foreach ($languages as $language) { - $language_name = $language->name; - $langcode = $language->id; + $language_name = $language->getName(); + $langcode = $language->getId(); $add_path = $rel['drupal:content-translation-overview'] . '/add/' . $original . '/' . $langcode; $translate_path = $rel['drupal:content-translation-overview'] . '/edit/' . $langcode; diff -u b/core/modules/language/language.module b/core/modules/language/language.module --- b/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -6,7 +6,7 @@ */ use Drupal\Core\PhpStorage\PhpStorageFactory; -use Drupal\Core\Language\Language; +use Drupal\Core\Language\LanguageInterface; use Drupal\language\ConfigurableLanguageManager; use Drupal\language\ConfigurableLanguageManagerInterface; use Drupal\language\Entity\Language as LanguageEntity; @@ -162,7 +162,7 @@ if (!isset($element['#options'])) { $element['#options'] = array(); foreach (\Drupal::languageManager()->getLanguages($element['#languages']) as $langcode => $language) { - $element['#options'][$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; + $element['#options'][$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName(); } } // Add "Built-in English" language to the select when the default value is @@ -208,9 +208,9 @@ 'authors_default' => t("Author's preferred language"), ); - $languages = \Drupal::languageManager()->getLanguages(Language::STATE_ALL); + $languages = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL); foreach ($languages as $langcode => $language) { - $language_options[$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; + $language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName(); } return $language_options; @@ -413,15 +413,15 @@ /** * API function to add or update a language. * - * @param $language + * @param \Drupal\Core\Language\LanguageInterface $language * Language object with properties corresponding to the 'language' * configuration properties. */ -function language_save($language) { - $language_entity = entity_load('language_entity', $language->id); +function language_save(LanguageInterface $language) { + $language_entity = entity_load('language_entity', $language->getId()); if (!$language_entity) { $language_entity = entity_create('language_entity', array( - 'id' => $language->id, + 'id' => $language->getId(), )); } $language->is_new = $language_entity->isNew(); @@ -435,7 +435,7 @@ // Save the record and inform others about the change. $multilingual = \Drupal::languageManager()->isMultilingual(); $language_entity->save(); - $t_args = array('%language' => $language->name, '%langcode' => $language->id); + $t_args = array('%language' => $language->name, '%langcode' => $language->getId()); if ($language->is_new) { watchdog('language', 'The %language (%langcode) language has been created.', $t_args); } @@ -443,10 +443,10 @@ watchdog('language', 'The %language (%langcode) language has been updated.', $t_args); } - if (!empty($language->default)) { + if ($language->isDefault()) { // Update the config. Saving the configuration fires and event that causes // the container to be rebuilt. - \Drupal::config('system.site')->set('langcode', $language->id)->save(); + \Drupal::config('system.site')->set('langcode', $language->getId())->save(); \Drupal::service('language.default')->set($language); } @@ -480,12 +480,12 @@ * TRUE if language is successfully deleted. Otherwise FALSE. */ function language_delete($langcode) { - $languages = \Drupal::languageManager()->getLanguages(Language::STATE_ALL); + $languages = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL); if (isset($languages[$langcode]) && !$languages[$langcode]->locked) { $language = $languages[$langcode]; // Remove the language. - entity_delete_multiple('language_entity', array($language->id)); + entity_delete_multiple('language_entity', array($language->getId())); $language_manager = \Drupal::languageManager(); $language_manager->reset(); @@ -499,7 +499,7 @@ ConfigurableLanguageManager::rebuildServices(); } - $t_args = array('%language' => $language->name, '%langcode' => $language->id); + $t_args = array('%language' => $language->getName(), '%langcode' => $language->getId()); watchdog('language', 'The %language (%langcode) language has been removed.', $t_args); return TRUE; } @@ -555,10 +555,10 @@ foreach (\Drupal::languageManager()->getLanguages() 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->id])) { + if (empty($prefixes[$language->getId()])) { // For the default language, set the prefix to the empty string, // otherwise use the langcode. - $prefixes[$language->id] = !empty($language->default) ? '' : $language->id; + $prefixes[$language->getId()] = $language->isDefault() ? '' : $language->getId(); } // Otherwise we keep the configured prefix. } @@ -706,5 +706,5 @@ $languages = \Drupal::languageManager()->getLanguages(); $language = $languages[$form_state['values']['site_default_language']]; - $language->default = TRUE; + $language->setDefault(TRUE); language_save($language); } diff -u b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php --- b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php @@ -77,7 +77,7 @@ language_save($default_language); language_delete('fr'); $result = \Drupal::languageManager()->getCurrentLanguage(); - $this->assertIdentical($result->getId(), $default_language->id); + $this->assertIdentical($result->getId(), $default_language->getId()); } } only in patch2: unchanged: --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -20,7 +20,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException as DependencyInjectionRuntimeException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Drupal\Core\Language\Language; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Lock\DatabaseLockBackend; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Session\AnonymousUserSession; @@ -1910,14 +1910,14 @@ function language($type) { * It can be: Language::STATE_CONFIGURABLE, Language::STATE_LOCKED, * Language::STATE_ALL. * - * @return array + * @return \Drupal\Core\Language\LanguageInterface[] * An associative array of languages, keyed by the language code, ordered by * weight ascending and name ascending. * * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. * Use \Drupal::languageManager()->getLanguages(). */ -function language_list($flags = Language::STATE_CONFIGURABLE) { +function language_list($flags = LanguageInterface::STATE_CONFIGURABLE) { return \Drupal::languageManager()->getLanguages($flags); } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Language/LanguageDefault.php +++ b/core/lib/Drupal/Core/Language/LanguageDefault.php @@ -22,7 +22,7 @@ class LanguageDefault { /** * The default language. * - * @var \Drupal\Core\Language\Language + * @var \Drupal\Core\Language\LanguageInterface */ protected $language; @@ -39,7 +39,7 @@ public function __construct(array $values) { /** * Gets the default language. * - * @return \Drupal\Core\Language\Language + * @return \Drupal\Core\Language\LanguageInterface * The default language. */ public function get() { @@ -49,11 +49,11 @@ public function get() { /** * Sets the default language. * - * @param \Drupal\Core\Language\Language $language + * @param \Drupal\Core\Language\LanguageInterface $language * The default language. */ - public function set(Language $language) { - $language->default = TRUE; + public function set(LanguageInterface $language) { + $language->setDefault(TRUE); $this->language = $language; } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Language/LanguageInterface.php +++ b/core/lib/Drupal/Core/Language/LanguageInterface.php @@ -208,4 +208,17 @@ public function getNegotiationMethodId(); */ public function setNegotiationMethodId($method_id); + /** + * Checks if the language is locked. + * + * Locked indicates a language used by the system, not an actual language. + * Examples of locked languages are, LANGCODE_NOT_SPECIFIED, und, and + * LANGCODE_NOT_APPLICABLE, zxx, which are usually shown in language selects + * but hidden in places like the Language configuration and cannot be deleted. + * + * @return bool + * TRUE if the language is locked. + */ + public function isLocked(); + } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -112,9 +112,9 @@ public function getLanguages($flags = Language::STATE_CONFIGURABLE) { if (!isset($this->languages)) { // No language module, so use the default language only. $default = $this->getDefaultLanguage(); - $this->languages = array($default->id => $default); + $this->languages = array($default->getId() => $default); // Add the special languages, they will be filtered later if needed. - $this->languages += $this->getDefaultLockedLanguages($default->weight); + $this->languages += $this->getDefaultLockedLanguages($default->getWeight()); } // Filter the full list of languages based on the value of the $all flag. By @@ -126,7 +126,7 @@ public function getLanguages($flags = Language::STATE_CONFIGURABLE) { if ($flags & Language::STATE_SITE_DEFAULT) { $default = isset($default) ? $default : $this->getDefaultLanguage(); // Rename the default language. - $default->name = $this->t("Site's default language (@lang_name)", array('@lang_name' => $default->name)); + $default->setName($this->t("Site's default language (@lang_name)", array('@lang_name' => $default->getName()))); $filtered_languages['site_default'] = $default; } @@ -155,7 +155,7 @@ public function getLanguageName($langcode) { return $this->t('None'); } if ($language = $this->getLanguage($langcode)) { - return $language->name; + return $language->getName(); } if (empty($langcode)) { return $this->t('Unknown'); @@ -339,7 +339,7 @@ public static function getStandardLanguageList() { * * @see \Drupal\language\ConfigurableLanguageManager::setConfigOverrideLanguage() */ - public function setConfigOverrideLanguage(Language $language = NULL) { + public function setConfigOverrideLanguage(LanguageInterface $language = NULL) { return $this; } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Language/LanguageManagerInterface.php +++ b/core/lib/Drupal/Core/Language/LanguageManagerInterface.php @@ -50,7 +50,7 @@ public function getLanguageTypes(); * (optional) The language type, e.g. the interface or the content language. * Defaults to \Drupal\Core\Language\Language::TYPE_INTERFACE. * - * @return \Drupal\Core\Language\Language + * @return \Drupal\Core\Language\LanguageInterface * A language object for the given type. */ public function getCurrentLanguage($type = Language::TYPE_INTERFACE); @@ -71,7 +71,7 @@ public function reset($type = NULL); /** * Returns a language object representing the site's default language. * - * @return \Drupal\Core\Language\Language + * @return \Drupal\Core\Language\LanguageInterface * A language object. */ public function getDefaultLanguage(); @@ -84,7 +84,7 @@ public function getDefaultLanguage(); * It can be: Language::STATE_CONFIGURABLE, * Language::STATE_LOCKED, Language::STATE_ALL. * - * @return array + * @return \Drupal\Core\Language\LanguageInterface[] array * An associative array of languages, keyed by the language code, ordered * by weight ascending and name ascending. */ @@ -96,7 +96,7 @@ public function getLanguages($flags = Language::STATE_CONFIGURABLE); * @param string $langcode * The language code. * - * @return \Drupal\core\Language\Language|null + * @return \Drupal\core\Language\LanguageInterface|null * A fully-populated language object or NULL. */ public function getLanguage($langcode); @@ -171,17 +171,17 @@ public function getLanguageSwitchLinks($type, $path); /** * Sets the configuration override language. * - * @param \Drupal\Core\Language\Language $language + * @param \Drupal\Core\Language\LanguageInterface $language * The language to override configuration with. * * @return $this */ - public function setConfigOverrideLanguage(Language $language = NULL); + public function setConfigOverrideLanguage(LanguageInterface $language = NULL); /** * Gets the current configuration override language. * - * @return \Drupal\Core\Language\Language $language + * @return \Drupal\Core\Language\LanguageInterface * The current configuration override language. */ public function getConfigOverrideLanguage(); only in patch2: unchanged: --- a/core/lib/Drupal/Core/TypedData/TranslatableInterface.php +++ b/core/lib/Drupal/Core/TypedData/TranslatableInterface.php @@ -29,7 +29,7 @@ public function language(); * (optional) Whether the default language should be included. Defaults to * TRUE. * - * @return + * @return \Drupal\Core\Language\LanguageInterface[] * An array of language objects, keyed by language codes. */ public function getTranslationLanguages($include_default = TRUE); only in patch2: unchanged: --- a/core/modules/block/lib/Drupal/block/BlockFormController.php +++ b/core/modules/block/lib/Drupal/block/BlockFormController.php @@ -174,7 +174,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->id] = $language->name; + $langcodes_options[$language->getId()] = $language->getName(); } $form['visibility']['language'] = array( '#type' => 'details', only in patch2: unchanged: --- a/core/modules/config/lib/Drupal/config/Tests/ConfigLanguageOverrideWebTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigLanguageOverrideWebTest.php @@ -72,7 +72,7 @@ function testSiteNameTranslation() { $language_manager = \Drupal::languageManager()->reset(); $this->assertTrue($language_manager->isMultilingual(), 'The test site is multilingual.'); $language = \Drupal::languageManager()->getLanguage('xx'); - $language->default = TRUE; + $language->setDefault(TRUE); language_save($language); language_delete('en'); $this->assertFalse($language_manager->isMultilingual(), 'The test site is monolingual.'); only in patch2: unchanged: --- a/core/modules/config/lib/Drupal/config/Tests/ConfigOverridesPriorityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigOverridesPriorityTest.php @@ -61,7 +61,7 @@ public function testOverridePriorities() { )); \Drupal::languageManager()->setConfigOverrideLanguage($language); \Drupal::languageManager() - ->getLanguageConfigOverride($language->id, 'system.site') + ->getLanguageConfigOverride($language->getId(), 'system.site') ->set('name', $language_overridden_name) ->set('mail', $language_overridden_mail) ->save(); only in patch2: unchanged: --- a/core/modules/config_translation/lib/Drupal/config_translation/Access/ConfigTranslationFormAccess.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Access/ConfigTranslationFormAccess.php @@ -32,8 +32,8 @@ public function access(Route $route, Request $request, AccountInterface $account // that is logically not a good idea. $access = !empty($target_language) && - !$target_language->locked && - $target_language->id != $this->sourceLanguage->id; + !$target_language->isLocked() && + $target_language->getId() != $this->sourceLanguage->getId(); return $access ? static::ALLOW : static::DENY; } only in patch2: unchanged: --- a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationController.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationController.php @@ -152,7 +152,7 @@ public function itemPage(Request $request, $plugin_id) { '#header' => array($this->t('Language'), $this->t('Operations')), ); foreach ($languages as $language) { - $langcode = $language->id; + $langcode = $language->getId(); // This is needed because // ConfigMapperInterface::getAddRouteParameters(), for example, @@ -163,7 +163,7 @@ public function itemPage(Request $request, $plugin_id) { // Prepare the language name and the operations depending on whether this // is the original language or not. if ($langcode == $original_langcode) { - $language_name = '' . $this->t('@language (original)', array('@language' => $language->name)) . ''; + $language_name = '' . $this->t('@language (original)', array('@language' => $language->getName())) . ''; // Check access for the path/route for editing, so we can decide to // include a link to edit or not. @@ -189,7 +189,7 @@ public function itemPage(Request $request, $plugin_id) { } } else { - $language_name = $language->name; + $language_name = $language->getName(); $operations = array(); // If no translation exists for this language, link to add one. only in patch2: unchanged: --- a/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationDeleteForm.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationDeleteForm.php @@ -137,7 +137,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU */ public function submitForm(array &$form, array &$form_state) { foreach ($this->mapper->getConfigNames() as $name) { - $this->languageManager->getLanguageConfigOverride($this->language->id, $name)->delete(); + $this->languageManager->getLanguageConfigOverride($this->language->getId(), $name)->delete(); } // Flush all persistent caches. only in patch2: unchanged: --- a/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php @@ -227,7 +227,7 @@ public function submitForm(array &$form, array &$form_state) { foreach ($this->mapper->getConfigNames() as $name) { // Set configuration values based on form submission and source values. $base_config = $this->config($name); - $config_translation = $this->languageManager->getLanguageConfigOverride($this->language->id, $name); + $config_translation = $this->languageManager->getLanguageConfigOverride($this->language->getId(), $name); $locations = $this->localeStorage->getLocations(array('type' => 'configuration', 'name' => $name)); $this->setConfig($this->language, $base_config, $config_translation, $form_values[$name], !empty($locations)); @@ -327,12 +327,12 @@ protected function buildConfigForm(Element $schema, $config_data, $base_config_d '#theme' => 'config_translation_manage_form_element', ); $build[$element_key]['source'] = array( - '#markup' => $base_config_data[$key] ? ('' . nl2br($base_config_data[$key] . '')) : t('(Empty)'), + '#markup' => $base_config_data[$key] ? ('' . nl2br($base_config_data[$key] . '')) : t('(Empty)'), '#title' => $this->t( '!label (!source_language)', array( '!label' => $this->t($definition['label']), - '!source_language' => $this->sourceLanguage->name, + '!source_language' => $this->sourceLanguage->getName(), ) ), '#type' => 'item', @@ -391,7 +391,7 @@ protected function setConfig(Language $language, Config $base_config, Config $co // Get the translation for this original source string from locale. $conditions = array( 'lid' => $source_string->lid, - 'language' => $language->id, + 'language' => $language->getId(), ); $translations = $this->localeStorage->getTranslations($conditions + array('translated' => TRUE)); // If we got a translation, take that, otherwise create a new one. only in patch2: unchanged: --- a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/DateFormat.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/FormElement/DateFormat.php @@ -30,10 +30,10 @@ public function getFormElement(array $definition, Language $language, $value) { $format = $this->t('Displayed as %date_format', array('%date_format' => \Drupal::service('date')->format(REQUEST_TIME, 'custom', $value))); return array( '#type' => 'textfield', - '#title' => $this->t($definition['label']) . ' (' . $language->name . ')', + '#title' => $this->t($definition['label']) . ' (' . $language->getName() . ')', '#description' => $description, '#default_value' => $value, - '#attributes' => array('lang' => $language->id), + '#attributes' => array('lang' => $language->getId()), '#field_suffix' => '
' . $format . '
', '#ajax' => array( 'callback' => 'Drupal\config_translation\FormElement\DateFormat::ajaxSample', only in patch2: unchanged: --- a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textarea.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textarea.php @@ -26,9 +26,9 @@ public function getFormElement(array $definition, Language $language, $value) { return array( '#type' => 'textarea', '#default_value' => $value, - '#title' => $this->t($definition['label']) . ' (' . $language->name . ')', + '#title' => $this->t($definition['label']) . ' (' . $language->getName() . ')', '#rows' => $rows, - '#attributes' => array('lang' => $language->id), + '#attributes' => array('lang' => $language->getId()), ); } only in patch2: unchanged: --- a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textfield.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textfield.php @@ -21,8 +21,8 @@ public function getFormElement(array $definition, Language $language, $value) { return array( '#type' => 'textfield', '#default_value' => $value, - '#title' => $this->t($definition['label']) . ' (' . $language->name . ')', - '#attributes' => array('lang' => $language->id), + '#title' => $this->t($definition['label']) . ' (' . $language->getName() . ')', + '#attributes' => array('lang' => $language->getId()), ); } only in patch2: unchanged: --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -161,14 +161,14 @@ function contact_mail($key, &$message, $params) { $variables['!sender-url'] = $params['sender']->getEmail(); } - $options = array('langcode' => $language->id); + $options = array('langcode' => $language->getId()); 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->id); + $build = entity_view($contact_message, 'mail', $language->getId()); $message['body'][] = drupal_render($build); break; @@ -187,7 +187,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->id); + $build = entity_view($contact_message, 'mail', $language->getId()); $message['body'][] = drupal_render($build); break; } only in patch2: unchanged: --- a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationHandler.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationHandler.php @@ -130,8 +130,8 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac ), ); foreach (language_list(Language::STATE_CONFIGURABLE) as $language) { - if (isset($translations[$language->id])) { - $form['source_langcode']['source']['#options'][$language->id] = $language->name; + if (isset($translations[$language->getId()])) { + $form['source_langcode']['source']['#options'][$language->getId()] = $language->getName(); } } } @@ -143,8 +143,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->id]) || $language->id == $entity_langcode) { - $form['langcode']['#options'][$language->id] = $language->name; + if (empty($translations[$language->getId()]) || $language->getId() == $entity_langcode) { + $form['langcode']['#options'][$language->getId()] = $language->getName(); } } } only in patch2: unchanged: --- a/core/modules/content_translation/lib/Drupal/content_translation/Form/ContentTranslationDeleteForm.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Form/ContentTranslationDeleteForm.php @@ -75,14 +75,14 @@ public function getCancelRoute() { */ public function submitForm(array &$form, array &$form_state) { // Remove the translated values. - $this->entity->removeTranslation($this->language->id); + $this->entity->removeTranslation($this->language->getId()); $this->entity->save(); // Remove any existing path alias for the removed translation. // @todo This should be taken care of by the Path module. if (\Drupal::moduleHandler()->moduleExists('path')) { $path = $this->entity->getSystemPath(); - $conditions = array('source' => $path, 'langcode' => $this->language->id); + $conditions = array('source' => $path, 'langcode' => $this->language->getId()); \Drupal::service('path.alias_storage')->delete($conditions); } only in patch2: unchanged: --- a/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php @@ -26,9 +26,11 @@ class FieldNormalizer extends NormalizerBase { * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() */ public function normalize($field, $format = NULL, array $context = array()) { + /** @var \Drupal\Core\Field\FieldItemInterface $field */ $normalized_field_items = array(); // Get the field definition. + /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $field->getEntity(); $field_name = $field->getName(); $field_definition = $field->getFieldDefinition(); only in patch2: unchanged: --- a/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverride.php +++ b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverride.php @@ -73,7 +73,7 @@ public function loadOverrides($names) { $data = $this->storage->readMultiple(array_values($language_names)); // Re-key the data array to use configuration names rather than override // names. - $prefix_length = strlen(static::LANGUAGE_CONFIG_PREFIX . '.' . $this->language->id) + 1; + $prefix_length = strlen(static::LANGUAGE_CONFIG_PREFIX . '.' . $this->language->getId()) + 1; foreach ($data as $key => $value) { unset($data[$key]); $key = substr($key, $prefix_length); @@ -109,7 +109,7 @@ protected function getLanguageConfigNames(array $names) { $language_names = array(); if (isset($this->language)) { foreach ($names as $name) { - if ($language_name = $this->getLanguageConfigName($this->language->id, $name)) { + if ($language_name = $this->getLanguageConfigName($this->language->getId(), $name)) { $language_names[$name] = $language_name; } } @@ -139,7 +139,7 @@ protected function getLanguageConfigName($langcode, $name) { * {@inheritdoc} */ public function getCacheSuffix() { - return $this->language ? $this->language->id : NULL; + return $this->language ? $this->language->getId() : NULL; } /** only in patch2: unchanged: --- a/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php +++ b/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php @@ -7,6 +7,7 @@ namespace Drupal\language; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\PhpStorage\PhpStorageFactory; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -274,7 +275,7 @@ public function getLanguages($flags = Language::STATE_CONFIGURABLE) { // Prepopulate the language list with the default language to keep things // working even if we have no configuration. $default = $this->getDefaultLanguage(); - $this->languages = array($default->id => $default); + $this->languages = array($default->getId() => $default); // Retrieve the config storage to list available languages. $prefix = 'language.entity.'; @@ -287,7 +288,7 @@ public function getLanguages($flags = Language::STATE_CONFIGURABLE) { $langcode = $data['id']; // Initialize default property so callers have an easy reference and can // save the same object without data loss. - $data['default'] = ($langcode == $default->id); + $data['default'] = ($langcode == $default->getId()); $data['name'] = $data['label']; $this->languages[$langcode] = new Language($data); $weight = max(array($weight, $this->languages[$langcode]->weight)); @@ -311,14 +312,14 @@ public function updateLockedLanguageWeights() { // Get maximum weight to update the system languages to keep them on bottom. foreach ($this->getLanguages(Language::STATE_CONFIGURABLE) as $language) { - if (!$language->locked && $language->weight > $max_weight) { - $max_weight = $language->weight; + if (!$language->isLocked() && $language->getWeight() > $max_weight) { + $max_weight = $language->getWeight(); } } // Loop locked languages to maintain the existing order. $locked_languages = $this->getLanguages(Language::STATE_LOCKED); - $config_ids = array_map(function($language) { return 'language.entity.' . $language->id; }, $locked_languages); + $config_ids = array_map(function(LanguageInterface $language) { return 'language.entity.' . $language->getId(); }, $locked_languages); foreach ($this->configFactory->loadMultiple($config_ids) as $config_id => $config) { // Update system languages weight. $max_weight++; @@ -388,7 +389,7 @@ public function getLanguageSwitchLinks($type, $path) { /** * {@inheritdoc} */ - public function setConfigOverrideLanguage(Language $language = NULL) { + public function setConfigOverrideLanguage(LanguageInterface $language = NULL) { $this->configFactoryOverride->setLanguage($language); return $this; } only in patch2: unchanged: --- a/core/modules/language/lib/Drupal/language/Entity/Language.php +++ b/core/modules/language/lib/Drupal/language/Entity/Language.php @@ -94,9 +94,10 @@ public function preSave(EntityStorageInterface $storage) { * @throws \RuntimeException */ public static function preDelete(EntityStorageInterface $storage, array $entities) { - $default_language = \Drupal::service('language.default')->get(); + /** @var \Drupal\Core\Language\LanguageDefault $language_default */ + $language_default = \Drupal::service('language.default'); foreach ($entities as $entity) { - if ($entity->id() == $default_language->id && !$entity->isUninstalling()) { + if ($entity->id() == $language_default->get()->getId() && !$entity->isUninstalling()) { throw new DeleteDefaultLanguageException('Can not delete the default language'); } } only in patch2: unchanged: --- a/core/modules/language/lib/Drupal/language/Form/NegotiationUrlForm.php +++ b/core/modules/language/lib/Drupal/language/Form/NegotiationUrlForm.php @@ -72,17 +72,17 @@ 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->id); + $t_args = array('%language' => $language->getName(), '%langcode' => $language->getId()); $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), + '#title' => $language->isDefault() ? t('%language (%langcode) path prefix (Default language)', $t_args) : t('%language (%langcode) path prefix', $t_args), '#maxlength' => 64, '#default_value' => isset($prefixes[$langcode]) ? $prefixes[$langcode] : '', '#field_prefix' => $base_url . '/', ); $form['domain'][$langcode] = array( '#type' => 'textfield', - '#title' => t('%language (%langcode) domain', array('%language' => $language->name, '%langcode' => $language->id)), + '#title' => t('%language (%langcode) domain', array('%language' => $language->getName(), '%langcode' => $language->getId())), '#maxlength' => 128, '#default_value' => isset($domains[$langcode]) ? $domains[$langcode] : '', ); @@ -105,7 +105,7 @@ public function validateForm(array &$form, array &$form_state) { $value = $form_state['values']['prefix'][$langcode]; if ($value === '') { - if (!$language->default && $form_state['values']['language_negotiation_url_part'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) { + if (!$language->isDefault() && $form_state['values']['language_negotiation_url_part'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) { // Throw a form error if the prefix is blank for a non-default language, // although it is required for selected negotiation type. $this->setFormError("prefix][$langcode", $form_state, t('The prefix may only be left blank for the default language.')); @@ -119,7 +119,7 @@ public function validateForm(array &$form, array &$form_state) { elseif (isset($count[$value]) && $count[$value] > 1) { // Throw a form error if there are two languages with the same // domain/prefix. - $this->setFormError("prefix][$langcode", $form_state, t('The prefix for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value))); + $this->setFormError("prefix][$langcode", $form_state, t('The prefix for %language, %value, is not unique.', array('%language' => $language->getName(), '%value' => $value))); } } @@ -129,7 +129,7 @@ public function validateForm(array &$form, array &$form_state) { $value = $form_state['values']['domain'][$langcode]; if ($value === '') { - if (!$language->default && $form_state['values']['language_negotiation_url_part'] == LanguageNegotiationUrl::CONFIG_DOMAIN) { + if (!$language->isDefault() && $form_state['values']['language_negotiation_url_part'] == LanguageNegotiationUrl::CONFIG_DOMAIN) { // Throw a form error if the domain is blank for a non-default language, // although it is required for selected negotiation type. $this->setFormError("domain][$langcode", $form_state, t('The domain may only be left blank for the default language.')); @@ -138,7 +138,7 @@ public function validateForm(array &$form, array &$form_state) { elseif (isset($count[$value]) && $count[$value] > 1) { // Throw a form error if there are two languages with the same // domain/domain. - $this->setFormError("domain][$langcode", $form_state, t('The domain for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value))); + $this->setFormError("domain][$langcode", $form_state, t('The domain for %language, %value, is not unique.', array('%language' => $language->getName(), '%value' => $value))); } } only in patch2: unchanged: --- a/core/modules/language/lib/Drupal/language/Tests/LanguageFallbackTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageFallbackTest.php @@ -30,8 +30,8 @@ protected function setUp() { for ($i = 0; $i < 3; $i++) { $language = new Language(); - $language->id = $this->randomName(2); - $language->weight = -$i; + $language->setId($this->randomName(2)); + $language->setWeight(-$i); language_save($language); } } @@ -63,7 +63,7 @@ public function testCandidates() { $this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable for specific operations.'); // Check that when the site is monolingual no language fallback is applied. - $default_langcode = $this->languageManager->getDefaultLanguage()->id; + $default_langcode = $this->languageManager->getDefaultLanguage()->getId(); foreach ($language_list as $langcode => $language) { if ($langcode != $default_langcode) { language_delete($langcode); only in patch2: unchanged: --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php @@ -7,6 +7,7 @@ namespace Drupal\language\Tests; +use Drupal\Core\Language\LanguageInterface; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\simpletest\WebTestBase; use Symfony\Component\HttpFoundation\Request; @@ -71,14 +72,13 @@ function testUrlRewritingEdgeCases() { * check that language prefixes are not added to it and that the prefixed URL * is actually not working. * - * @param string $language - * The language prefix, e.g. 'es'. + * @param \Drupal\Core\Language\LanguageInterface $language * @param string $message1 * Message to display in assertion that language prefixes are not added. * @param string $message2 * The message to display confirming prefixed URL is not working. */ - private function checkUrl($language, $message1, $message2) { + private function checkUrl(LanguageInterface $language, $message1, $message2) { $options = array('language' => $language, 'script' => ''); $base_path = trim(base_path(), '/'); $rewritten_path = trim(str_replace($base_path, '', url('node', $options)), '/'); @@ -89,7 +89,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->id]) ? $prefixes[$language->id] : $this->randomName(); + $stored_prefix = isset($prefixes[$language->getId()]) ? $prefixes[$language->getId()] : $this->randomName(); if ($this->assertNotEqual($stored_prefix, $prefix, $message1)) { $prefix = $stored_prefix; } only in patch2: unchanged: --- a/core/modules/locale/lib/Drupal/locale/Form/ExportForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/ExportForm.php @@ -61,7 +61,7 @@ public function buildForm(array $form, array &$form_state) { $language_options = array(); foreach ($languages as $langcode => $language) { if ($langcode != 'en' || locale_translate_english()) { - $language_options[$langcode] = $language->name; + $language_options[$langcode] = $language->getName(); } } $language_default = $this->languageManager->getDefaultLanguage(); @@ -82,7 +82,7 @@ public function buildForm(array $form, array &$form_state) { '#type' => 'select', '#title' => $this->t('Language'), '#options' => $language_options, - '#default_value' => $language_default->id, + '#default_value' => $language_default->getId(), '#empty_option' => $this->t('Source text only, no translations'), '#empty_value' => Language::LANGCODE_SYSTEM, ); @@ -139,11 +139,11 @@ public function submitForm(array &$form, array &$form_state) { $reader = new PoDatabaseReader(); $languageName = ''; if ($language != NULL) { - $reader->setLangcode($language->id); + $reader->setLangcode($language->getId()); $reader->setOptions($content_options); $languages = $this->languageManager->getLanguages(); - $languageName = isset($languages[$language->id]) ? $languages[$language->id]->name : ''; - $filename = $language->id .'.po'; + $languageName = isset($languages[$language->getId()]) ? $languages[$language->getId()]->getName() : ''; + $filename = $language->getId() .'.po'; } else { // Template required. only in patch2: unchanged: --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php @@ -8,10 +8,10 @@ namespace Drupal\locale; use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Language\Language; use Drupal\Core\Config\TypedConfigManager; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Language\LanguageInterface; use Drupal\language\Config\LanguageConfigFactoryOverrideInterface; use Drupal\language\ConfigurableLanguageManagerInterface; @@ -308,14 +308,14 @@ public function translateString($name, $langcode, $source, $context) { * * @param string $name * Configuration name. - * @param \Drupal\Core\Language\Language $language + * @param \Drupal\Core\Language\LanguageInterface $language * A language object. * * @return bool * A boolean indicating if a language has configuration translations. */ - public function hasTranslation($name, Language $language) { - $translation = $this->languageManager->getLanguageConfigOverride($language->id, $name); + public function hasTranslation($name, LanguageInterface $language) { + $translation = $this->languageManager->getLanguageConfigOverride($language->getId(), $name); return !$translation->isNew(); } only in patch2: unchanged: --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php @@ -195,8 +195,10 @@ function buildSourceString($values = array()) { */ function createAllTranslations($source, $values = array()) { $list = array(); - foreach ($this->container->get('language_manager')->getLanguages() as $language) { - $list[$language->id] = $this->createTranslation($source, $language->id, $values); + /** @var \Drupal\Core\Language\LanguageManagerInterface $language_manager */ + $language_manager = $this->container->get('language_manager'); + foreach ($language_manager->getLanguages() as $language) { + $list[$language->getId()] = $this->createTranslation($source, $language->getId(), $values); } return $list; } only in patch2: unchanged: --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php @@ -180,7 +180,7 @@ function testMenuLanguageRemovedEnglish() { // Remove English language. To do that another language has to be set as // default. $language = language_load('cs'); - $language->default = TRUE; + $language->setDefault(TRUE); language_save($language); language_delete('en'); only in patch2: unchanged: --- a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php @@ -326,23 +326,23 @@ protected function indexNode(NodeInterface $node) { $node_render = $this->entityManager->getViewBuilder('node'); foreach ($languages as $language) { - $node = $node->getTranslation($language->id); + $node = $node->getTranslation($language->getId()); // Render the node. - $build = $node_render->view($node, 'search_index', $language->id); + $build = $node_render->view($node, 'search_index', $language->getId()); unset($build['#theme']); $node->rendered = drupal_render($build); - $text = '

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

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

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

' . $node->rendered; // Fetch extra data normally not visible. - $extra = $this->moduleHandler->invokeAll('node_update_index', array($node, $language->id)); + $extra = $this->moduleHandler->invokeAll('node_update_index', array($node, $language->getId())); foreach ($extra as $t) { $text .= $t; } // Update index. - search_index($node->id(), $this->getPluginId(), $text, $language->id); + search_index($node->id(), $this->getPluginId(), $text, $language->getId()); } } only in patch2: unchanged: --- a/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php @@ -66,7 +66,7 @@ function testLinkAttributes() { '#href' => 'http://drupal.org', '#title' => 'bar', ); - $langcode = $language->id; + $langcode = $language->getId(); // Test that the default hreflang handling for links does not override a // hreflang attribute explicitly set in the render array. only in patch2: unchanged: --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityLanguageTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityLanguageTestBase.php @@ -119,7 +119,7 @@ function setUp() { 'name' => $this->randomString(), 'weight' => $i, )); - $this->langcodes[$i] = $language->id; + $this->langcodes[$i] = $language->getId(); language_save($language); } } only in patch2: unchanged: --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php @@ -44,7 +44,7 @@ function setUp() { 'id' => 'l' . $i, 'name' => $this->randomString(), )); - $this->langcodes[$i] = $language->id; + $this->langcodes[$i] = $language->getId(); language_save($language); } } only in patch2: unchanged: --- a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigTransTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigTransTest.php @@ -81,12 +81,12 @@ protected function setUp() { // Assign Lolspeak (xx) to be the default language. $language = \Drupal::languageManager()->getLanguage('xx'); - $language->default = TRUE; + $language->setDefault(TRUE); language_save($language); $this->rebuildContainer(); // Check that lolspeak is the default language for the site. - $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->id, 'xx', 'Lolspeak is the default language'); + $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), 'xx', 'Lolspeak is the default language'); } /** only in patch2: unchanged: --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -791,7 +791,7 @@ function taxonomy_build_node_index($node) { $field_name = $field->getName(); if ($field->module == 'taxonomy') { foreach ($node->getTranslationLanguages() as $language) { - foreach ($node->getTranslation($language->id)->$field_name as $item) { + foreach ($node->getTranslation($language->getId())->$field_name as $item) { if (!$item->isEmpty()) { $tid_all[$item->target_id] = $item->target_id; } only in patch2: unchanged: --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -518,7 +518,7 @@ function views_language_list($field = 'name', $flags = Language::STATE_ALL) { $languages = \Drupal::languageManager()->getLanguages($flags); $list = array(); foreach ($languages as $language) { - $list[$language->id] = ($field == 'name') ? t($language->name) : $language->$field; + $list[$language->getId()] = ($field == 'name') ? t($language->getName()) : $language->$field; } return $list; } only in patch2: unchanged: --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -843,7 +843,7 @@ function testgetExtraFields() { $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $language_code; $language = new Language(); - $language->id = $language_code; + $language->setId($language_code); $this->languageManager->expects($this->once()) ->method('getCurrentLanguage') only in patch2: unchanged: --- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php @@ -26,6 +26,9 @@ */ class PathProcessorTest extends UnitTestCase { + /** + * @var \Drupal\Core\Language\LanguageInterface[] + */ protected $languages; protected $languageManager; @@ -42,9 +45,13 @@ public function setUp() { // Set up some languages to be used by the language-based path processor. $languages = array(); foreach (array('en' => 'English', 'fr' => 'French') as $langcode => $language_name) { - $language = new \stdClass(); - $language->id = $langcode; - $language->name = $language_name; + $language = $this->getMock('\Drupal\Core\Language\LanguageInterface'); + $language->expects($this->any()) + ->method('getId') + ->will($this->returnValue($langcode)); + $language->expects($this->any()) + ->method('getName') + ->will($this->returnValue($language_name)); $languages[$langcode] = $language; } $this->languages = $languages;