diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index a9ea984..7f5ef54 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1785,7 +1785,7 @@ function drupal_installation_attempted() { * @see \Drupal\Core\Language\LanguageManager * * @param string $type - * The type of language object needed, e.g. Language::TYPE_INTERFACE. + * The type of language object needed, e.g. LanguageInterface::TYPE_INTERFACE. * * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. * Use \Drupal::languageManager()->getCurrentLanguage(). @@ -1800,9 +1800,9 @@ function language($type) { * @param $flags * (optional) Specifies the state of the languages that have to be returned. * It can be: LanguageInterface::STATE_CONFIGURABLE, - * LanguageInterface::STATE_LOCKED, LanguageInterface::STATE_ALL. + * LanguageInterface::STATE_LOCKED or LanguageInterface::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. * diff --git a/core/includes/common.inc b/core/includes/common.inc index 3f0fd1d..e8a8908 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -415,7 +415,7 @@ function check_url($uri) { * 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 : \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id; + $langcode = $langcode ? $langcode : \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); $output = "\n"; $output .= ' ' . String::checkPlain($title) . "\n"; @@ -847,7 +847,7 @@ function l($text, $path, array $options = array()) { // Add a hreflang attribute if we know the language of this link's url and // hreflang has not already been set. if (!empty($variables['options']['language']) && !isset($variables['options']['attributes']['hreflang'])) { - $variables['options']['attributes']['hreflang'] = $variables['options']['language']->id; + $variables['options']['attributes']['hreflang'] = $variables['options']['language']->getId(); } // Set the "active" class if the 'set_active_class' option is not empty. @@ -1773,7 +1773,7 @@ function _drupal_add_js($data = NULL, $options = NULL) { 'currentPath' => $current_path, 'currentPathIsAdmin' => $current_path_is_admin, 'isFront' => drupal_is_front_page(), - 'currentLanguage' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL)->id, + 'currentLanguage' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(), ); if (!empty($current_query)) { ksort($current_query); diff --git a/core/includes/form.inc b/core/includes/form.inc index cc4bcdb..0f0d39a 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2029,7 +2029,7 @@ function form_process_machine_name($element, &$form_state) { 'machineName' => array( '#' . $source['#id'] => $element['#machine_name'], ), - 'langcode' => $language->id, + 'langcode' => $language->getId(), ), ); $element['#attached']['library'][] = 'core/drupal.machine-name'; diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 03d0df0..101c5f3 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1212,7 +1212,7 @@ function template_preprocess_links(&$variables) { $link_element['#options']['set_active_class'] = TRUE; if (!empty($link['language'])) { - $li_attributes['hreflang'] = $link['language']->id; + $li_attributes['hreflang'] = $link['language']->getId(); } // Add a "data-drupal-link-query" attribute to let the @@ -2075,7 +2075,7 @@ function template_preprocess_page(&$variables) { $variables['base_path'] = base_path(); $variables['front_page'] = url(); $variables['language'] = $language_interface; - $variables['language']->dir = $language_interface->direction ? 'rtl' : 'ltr'; + $variables['language']->dir = $language_interface->getDirection() ? 'rtl' : 'ltr'; $variables['logo'] = theme_get_setting('logo.url'); $variables['site_name'] = (theme_get_setting('features.name') ? String::checkPlain($site_config->get('name')) : ''); $variables['site_slogan'] = (theme_get_setting('features.slogan') ? Xss::filterAdmin($site_config->get('slogan')) : ''); diff --git a/core/includes/update.inc b/core/includes/update.inc index 945ffe7..27a965a 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -13,6 +13,8 @@ use Drupal\Core\Config\FileStorage; use Drupal\Core\Config\ConfigException; use Drupal\Core\DrupalKernel; +use Drupal\Core\Language\Language; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Page\DefaultHtmlPageRenderer; use Drupal\Core\Utility\Error; use Drupal\Component\Uuid\Uuid; @@ -801,7 +803,7 @@ function update_replace_permissions($replace) { * @param $flags * (optional) Specifies the state of the languages that have to be returned. * It can be: LanguageInterface::STATE_CONFIGURABLE, - * LanguageInterface::STATE_LOCKED, LanguageInterface::STATE_ALL. + * LanguageInterface::STATE_LOCKED or LanguageInterface::STATE_ALL. * * @return array * An associative array of languages, keyed by the language code, ordered by @@ -829,7 +831,7 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) { $langcode = substr($langcode_config_name, strlen('language.entity.')); $info = \Drupal::config($langcode_config_name)->get(); $languages[$langcode] = new Language(array( - 'default' => ($info['id'] == $default->id), + 'default' => ($info['id'] == $default->getId()), 'name' => $info['label'], 'id' => $info['id'], 'direction' => $info['direction'], @@ -837,13 +839,13 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) { 'weight' => $info['weight'], )); } - Language::sort($languages); + uasort($languages, '\Drupal\Core\Language\Language::sort'); } else { // No language module, so use the default language only. - $languages = array($default->id => $default); + $languages = array($default->getId() => $default); // Add the special languages, they will be filtered later if needed. - $languages += \Drupal::languageManager()->getDefaultLockedLanguages($default->weight); + $languages += \Drupal::languageManager()->getDefaultLockedLanguages($default->getWeight()); } } @@ -861,7 +863,7 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) { } foreach ($languages as $langcode => $language) { - if (($language->locked && !($flags & LanguageInterface::STATE_LOCKED)) || (!$language->locked && !($flags & LanguageInterface::STATE_CONFIGURABLE))) { + if (($language->isLocked() && !($flags & LanguageInterface::STATE_LOCKED)) || (!$language->isLocked() && !($flags & LanguageInterface::STATE_CONFIGURABLE))) { continue; } $filtered_languages[$langcode] = $language; diff --git a/core/lib/Drupal/Core/Cache/LanguageCacheContext.php b/core/lib/Drupal/Core/Cache/LanguageCacheContext.php index e2c1bd9..0a3f16c 100644 --- a/core/lib/Drupal/Core/Cache/LanguageCacheContext.php +++ b/core/lib/Drupal/Core/Cache/LanguageCacheContext.php @@ -45,7 +45,7 @@ public function getContext() { $context_parts = array(); if ($this->languageManager->isMultilingual()) { foreach ($this->languageManager->getLanguageTypes() as $type) { - $context_parts[] = $this->languageManager->getCurrentLanguage($type)->id; + $context_parts[] = $this->languageManager->getCurrentLanguage($type)->getId(); } } return implode(':', $context_parts); diff --git a/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php b/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php index 84954f7..3ea3dd4 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php +++ b/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php @@ -7,8 +7,6 @@ namespace Drupal\Core\Config; -use Drupal\Core\Language\LanguageDefault; - /** * Defines the interface for a configuration object factory. */ diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php index b355cb5..ee1c9f0 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -109,7 +109,7 @@ public function isSyncing(); * entity change is part of an uninstall process, and skip executing your code * if that is the case. * - * For example, \Drupal\language\Entity\Language::preDelete() prevents the API + * For example, \Drupal\language\Entity\LanguageInterface::preDelete() prevents the API * from deleting the default language. However during an uninstall of the * language module it is expected that the default language should be deleted. * diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index d23341b..cec215d 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -183,7 +183,7 @@ protected function doLoadMultiple(array $ids = NULL) { */ protected function doCreate(array $values) { // Set default language to site default if not provided. - $values += array('langcode' => $this->languageManager->getDefaultLanguage()->id); + $values += array('langcode' => $this->languageManager->getDefaultLanguage()->getId()); $entity = new $this->entityClass($values, $this->entityTypeId); // Default status to enabled. diff --git a/core/lib/Drupal/Core/Datetime/Date.php b/core/lib/Drupal/Core/Datetime/Date.php index 2a31eb7..8b1ae64 100644 --- a/core/lib/Drupal/Core/Datetime/Date.php +++ b/core/lib/Drupal/Core/Datetime/Date.php @@ -132,7 +132,7 @@ public function format($timestamp, $type = 'medium', $format = '', $timezone = N } if (empty($langcode)) { - $langcode = $this->languageManager->getCurrentLanguage()->id; + $langcode = $this->languageManager->getCurrentLanguage()->getId(); } // 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 78b3f1c..2f07108 100644 --- a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php +++ b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php @@ -43,7 +43,7 @@ class DrupalDateTime extends DateTimePlus { */ public function __construct($time = 'now', $timezone = NULL, $settings = array()) { if (!isset($settings['langcode'])) { - $settings['langcode'] = \Drupal::languageManager()->getCurrentLanguage()->id; + $settings['langcode'] = \Drupal::languageManager()->getCurrentLanguage()->getId(); } // Instantiate the parent class. diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 9716ccc..762d212 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -572,7 +572,7 @@ public function language() { protected function setDefaultLangcode() { // Get the language code if the property exists. if ($this->hasField('langcode') && ($item = $this->get('langcode')) && isset($item->language)) { - $this->defaultLangcode = $item->language->id; + $this->defaultLangcode = $item->language->getId(); } if (empty($this->defaultLangcode)) { // Make sure we return a proper language object. @@ -654,7 +654,7 @@ public function getTranslation($langcode) { // If the entity or the requested language is not a configured // language, we fall back to the entity itself, since in this case it // cannot have translations. - $translation = empty($this->languages[$this->defaultLangcode]->locked) && empty($this->languages[$langcode]->locked) ? $this->addTranslation($langcode) : $this; + $translation = !$this->languages[$this->defaultLangcode]->isLocked() && !$this->languages[$langcode]->isLocked() ? $this->addTranslation($langcode) : $this; } } } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index b51272c..174c668 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -878,8 +878,8 @@ protected function mapToDataStorageRecord(EntityInterface $entity, $table_name = $table_name = $this->dataTable; } $record = $this->mapToStorageRecord($entity, $table_name); - $record->langcode = $entity->language()->id; - $record->default_langcode = intval($record->langcode == $entity->getUntranslated()->language()->id); + $record->langcode = $entity->language()->getId(); + $record->default_langcode = intval($record->langcode == $entity->getUntranslated()->language()->getId()); return $record; } @@ -939,6 +939,7 @@ public function getQueryServiceName() { * {@inheritdoc} */ protected function doLoadFieldItems($entities, $age) { + /** @var \Drupal\Core\Entity\ContentEntityInterface[] $entities */ $load_current = $age == static::FIELD_LOAD_CURRENT; // Collect entities ids, bundles and languages. @@ -948,7 +949,7 @@ protected function doLoadFieldItems($entities, $age) { foreach ($entities as $key => $entity) { $bundles[$entity->bundle()] = TRUE; $ids[] = $load_current ? $key : $entity->getRevisionId(); - $default_langcodes[$key] = $entity->getUntranslated()->language()->id; + $default_langcodes[$key] = $entity->getUntranslated()->language()->getId(); } // Collect impacted fields. @@ -1010,11 +1011,12 @@ protected function doLoadFieldItems($entities, $age) { * {@inheritdoc} */ protected function doSaveFieldItems(EntityInterface $entity, $update) { + /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $vid = $entity->getRevisionId(); $id = $entity->id(); $bundle = $entity->bundle(); $entity_type = $entity->getEntityTypeId(); - $default_langcode = $entity->getUntranslated()->language()->id; + $default_langcode = $entity->getUntranslated()->language()->getId(); $translation_langcodes = array_keys($entity->getTranslationLanguages()); if (!isset($vid)) { diff --git a/core/lib/Drupal/Core/Entity/ContentEntityForm.php b/core/lib/Drupal/Core/Entity/ContentEntityForm.php index 8722a9c..aa003d6 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityForm.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php @@ -90,7 +90,7 @@ public function getFormLangcode(array &$form_state) { // Imply a 'view' operation to ensure users edit entities in the same // language they are displayed. This allows to keep contextual editing // working also for multilingual entities. - $form_state['langcode'] = $this->entityManager->getTranslationFromContext($this->entity)->language()->id; + $form_state['langcode'] = $this->entityManager->getTranslationFromContext($this->entity)->language()->getId(); } return $form_state['langcode']; } @@ -99,7 +99,7 @@ public function getFormLangcode(array &$form_state) { * {@inheritdoc} */ public function isDefaultFormLangcode(array $form_state) { - return $this->getFormLangcode($form_state) == $this->entity->getUntranslated()->language()->id; + return $this->getFormLangcode($form_state) == $this->entity->getUntranslated()->language()->getId(); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityForm.php b/core/lib/Drupal/Core/Entity/EntityForm.php index dcb9aae..7982e8b 100644 --- a/core/lib/Drupal/Core/Entity/EntityForm.php +++ b/core/lib/Drupal/Core/Entity/EntityForm.php @@ -145,7 +145,7 @@ public function form(array $form, array &$form_state) { // new entities. $form['langcode'] = array( '#type' => 'value', - '#value' => !$entity->isNew() ? $entity->language()->id : language_default()->id, + '#value' => !$entity->isNew() ? $entity->language()->getId() : language_default()->getId(), ); } return $form; @@ -287,7 +287,7 @@ public function save(array $form, array &$form_state) { * {@inheritdoc} */ public function getFormLangcode(array &$form_state) { - return $this->entity->language()->id; + return $this->entity->language()->getId(); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 5e2ad03..20b69d7 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -330,7 +330,7 @@ public function getBaseFieldDefinitions($entity_type_id) { // Check the static cache. if (!isset($this->baseFieldDefinitions[$entity_type_id])) { // Not prepared, try to load from cache. - $cid = 'entity_base_field_definitions:' . $entity_type_id . ':' . $this->languageManager->getCurrentLanguage()->id; + $cid = 'entity_base_field_definitions:' . $entity_type_id . ':' . $this->languageManager->getCurrentLanguage()->getId(); if ($cache = $this->cacheBackend->get($cid)) { $this->baseFieldDefinitions[$entity_type_id] = $cache->data; } @@ -426,7 +426,7 @@ public function getFieldDefinitions($entity_type_id, $bundle) { if (!isset($this->fieldDefinitions[$entity_type_id][$bundle])) { $base_field_definitions = $this->getBaseFieldDefinitions($entity_type_id); // Not prepared, try to load from cache. - $cid = 'entity_bundle_field_definitions:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager->getCurrentLanguage()->id; + $cid = 'entity_bundle_field_definitions:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager->getCurrentLanguage()->getId(); if ($cache = $this->cacheBackend->get($cid)) { $bundle_field_definitions = $cache->data; } @@ -518,7 +518,7 @@ public function getFieldStorageDefinitions($entity_type_id) { } } // Not prepared, try to load from cache. - $cid = 'entity_field_storage_definitions:' . $entity_type_id . ':' . $this->languageManager->getCurrentLanguage()->id; + $cid = 'entity_field_storage_definitions:' . $entity_type_id . ':' . $this->languageManager->getCurrentLanguage()->getId(); if ($cache = $this->cacheBackend->get($cid)) { $field_storage_definitions = $cache->data; } @@ -637,7 +637,7 @@ public function getBundleInfo($entity_type) { */ public function getAllBundleInfo() { if (empty($this->bundleInfo)) { - $langcode = $this->languageManager->getCurrentLanguage()->id; + $langcode = $this->languageManager->getCurrentLanguage()->getId(); if ($cache = $this->cacheBackend->get("entity_bundle_info:$langcode")) { $this->bundleInfo = $cache->data; } @@ -678,7 +678,7 @@ public function getExtraFields($entity_type_id, $bundle) { // Read from the persistent cache. Since hook_entity_extra_field_info() and // hook_entity_extra_field_info_alter() might contain t() calls, we cache // per language. - $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager->getCurrentLanguage()->id; + $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager->getCurrentLanguage()->getId(); $cached = $this->cacheBackend->get($cache_id); if ($cached) { $this->extraFields[$entity_type_id][$bundle] = $cached->data; @@ -740,7 +740,7 @@ public function getTranslationFromContext(EntityInterface $entity, $langcode = N if ($entity instanceof TranslatableInterface) { if (empty($langcode)) { - $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id; + $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); } // Retrieve language fallback candidates to perform the entity language @@ -751,7 +751,7 @@ public function getTranslationFromContext(EntityInterface $entity, $langcode = N // Ensure the default language has the proper language code. $default_language = $entity->getUntranslated()->language(); - $candidates[$default_language->id] = LanguageInterface::LANGCODE_DEFAULT; + $candidates[$default_language->getId()] = LanguageInterface::LANGCODE_DEFAULT; // Return the most fitting entity translation. foreach ($candidates as $candidate) { @@ -805,7 +805,7 @@ public function getFormModes($entity_type_id) { protected function getAllDisplayModesByEntityType($display_type) { if (!isset($this->displayModeInfo[$display_type])) { $key = 'entity_' . $display_type . '_info'; - $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_INTERFACE)->id; + $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_INTERFACE)->getId(); if ($cache = $this->cacheBackend->get("$key:$langcode")) { $this->displayModeInfo[$display_type] = $cache->data; } diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 23a4ebf..54014ee 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -109,7 +109,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 = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id; + $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); } $build_list = array( diff --git a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php index 442162c..30c65ca 100644 --- a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php @@ -94,7 +94,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI */ public function doCreate(array $values = array()) { // Set default language to site default if not provided. - $values += array('langcode' => $this->languageManager->getDefaultLanguage()->id); + $values += array('langcode' => $this->languageManager->getDefaultLanguage()->getId()); $entity = new $this->entityClass($values, $this->entityTypeId); // @todo This is handled by ContentEntityStorageBase, which assumes diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 605d979..37322ec 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -69,7 +69,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->getCurrentLanguage()->id); + $response->headers->set('Content-language', $this->languageManager->getCurrentLanguage()->getId()); // Attach globally-declared headers to the response object so that Symfony // can send them for us correctly. diff --git a/core/lib/Drupal/Core/Language/Language.php b/core/lib/Drupal/Core/Language/Language.php index 9bfc10b..05e34be 100644 --- a/core/lib/Drupal/Core/Language/Language.php +++ b/core/lib/Drupal/Core/Language/Language.php @@ -35,14 +35,14 @@ class Language implements LanguageInterface { * * @var string */ - public $name = ''; + protected $name = ''; /** * The ID, langcode. * * @var string */ - public $id = ''; + protected $id = ''; /** * The direction, left-to-right, or right-to-left. @@ -51,21 +51,21 @@ class Language implements LanguageInterface { * * @var int */ - public $direction = self::DIRECTION_LTR; + protected $direction = self::DIRECTION_LTR; /** * The weight, used for ordering languages in lists, like selects or tables. * * @var int */ - public $weight = 0; + protected $weight = 0; /** * Flag indicating if this is the only site default language. * * @var bool */ - public $default = FALSE; + protected $default = FALSE; /** * The language negotiation method used when a language was detected. @@ -75,7 +75,7 @@ class Language implements LanguageInterface { * * @var string */ - public $method_id; + protected $negotiationMethodId; /** * Locked indicates a language used by the system, not an actual language. @@ -86,7 +86,7 @@ class Language implements LanguageInterface { * * @var bool */ - public $locked = FALSE; + protected $locked = FALSE; /** * Constructs a new class instance. @@ -198,26 +198,43 @@ public function setDefault($default) { * {@inheritdoc} */ public function getNegotiationMethodId() { - return $this->method_id; + return $this->negotiationMethodId; } /** * {@inheritdoc} */ public function setNegotiationMethodId($method_id) { - $this->method_id = $method_id; + $this->negotiationMethodId = $method_id; return $this; } /** + * {@inheritdoc} + */ + public function isLocked() { + return $this->locked; + } + + /** * Sort language objects. * - * @param array $languages - * The array of language objects keyed by langcode. + * This is a sort() callback. + * + * @param \Drupal\Core\Language\LanguageInterface $a + * @param \Drupal\Core\Language\LanguageInterface $b + * + * @return int + * -1, 0, or 1. */ - public static function sort(&$languages) { - uasort($languages, 'Drupal\Component\Utility\SortArray::sortByWeightAndTitleKey'); + public static function sort(LanguageInterface $a, LanguageInterface $b) { + if ($a->getWeight() == $b->getWeight()) { + return strnatcasecmp($a->getName(), $b->getName()); + } + else { + return $a->getWeight() < $b->getWeight() ? -1 : 1; + } } } diff --git a/core/lib/Drupal/Core/Language/LanguageDefault.php b/core/lib/Drupal/Core/Language/LanguageDefault.php index 1ca8009..53f40d2 100644 --- a/core/lib/Drupal/Core/Language/LanguageDefault.php +++ b/core/lib/Drupal/Core/Language/LanguageDefault.php @@ -53,7 +53,7 @@ public function get() { * The default language. */ public function set(LanguageInterface $language) { - $language->default = TRUE; + $language->setDefault(TRUE); $this->language = $language; } diff --git a/core/lib/Drupal/Core/Language/LanguageInterface.php b/core/lib/Drupal/Core/Language/LanguageInterface.php index e718749..d3977b4 100644 --- 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(); + } diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index d596853..d738f5a 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -26,7 +26,7 @@ class LanguageManager extends DependencySerialization implements LanguageManager /** * An array of all the available languages keyed by language code. * - * @var array + * @var \Drupal\Core\Language\LanguageInterface[] */ protected $languages; @@ -112,9 +112,9 @@ public function getLanguages($flags = LanguageInterface::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,12 +126,12 @@ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { if ($flags & LanguageInterface::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; } foreach ($this->languages as $id => $language) { - if (($language->locked && ($flags & LanguageInterface::STATE_LOCKED)) || (!$language->locked && ($flags & LanguageInterface::STATE_CONFIGURABLE))) { + if (($language->isLocked() && ($flags & LanguageInterface::STATE_LOCKED)) || (!$language->isLocked() && ($flags & LanguageInterface::STATE_CONFIGURABLE))) { $filtered_languages[$id] = $language; } } @@ -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'); @@ -193,7 +193,7 @@ public function getDefaultLockedLanguages($weight = 0) { */ public function isLanguageLocked($langcode) { $language = $this->getLanguage($langcode); - return ($language ? $language->locked : FALSE); + return ($language ? $language->isLocked() : FALSE); } /** diff --git a/core/lib/Drupal/Core/Language/LanguageManagerInterface.php b/core/lib/Drupal/Core/Language/LanguageManagerInterface.php index dd481a7..3b7d940 100644 --- a/core/lib/Drupal/Core/Language/LanguageManagerInterface.php +++ b/core/lib/Drupal/Core/Language/LanguageManagerInterface.php @@ -84,7 +84,7 @@ public function getDefaultLanguage(); * It can be: LanguageInterface::STATE_CONFIGURABLE, * LanguageInterface::STATE_LOCKED, LanguageInterface::STATE_ALL. * - * @return array + * @return \Drupal\Core\Language\LanguageInterface[] * An associative array of languages, keyed by the language code. */ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE); @@ -180,7 +180,7 @@ public function setConfigOverrideLanguage(LanguageInterface $language = NULL); /** * Gets the current configuration override language. * - * @return \Drupal\Core\Language\LanguageInterface $language + * @return \Drupal\Core\Language\LanguageInterface * The current configuration override language. */ public function getConfigOverrideLanguage(); diff --git a/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php b/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php index f2429d9..91463ba 100644 --- a/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php +++ b/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php @@ -88,8 +88,8 @@ public function preparePage(HtmlPage $page, &$page_array) { // HTML element attributes. $language_interface = $this->languageManager->getCurrentLanguage(); $html_attributes = $page->getHtmlAttributes(); - $html_attributes['lang'] = $language_interface->id; - $html_attributes['dir'] = $language_interface->direction ? 'rtl' : 'ltr'; + $html_attributes['lang'] = $language_interface->getId(); + $html_attributes['dir'] = $language_interface->getDirection() ? 'rtl' : 'ltr'; $this->setDefaultMetaTags($page); diff --git a/core/lib/Drupal/Core/Path/AliasManager.php b/core/lib/Drupal/Core/Path/AliasManager.php index e22ceea..5110592 100644 --- a/core/lib/Drupal/Core/Path/AliasManager.php +++ b/core/lib/Drupal/Core/Path/AliasManager.php @@ -10,7 +10,6 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\CacheDecorator\CacheDecoratorInterface; use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\Language\LanguageManager; use Drupal\Core\Language\LanguageManagerInterface; class AliasManager implements AliasManagerInterface, CacheDecoratorInterface { @@ -158,7 +157,7 @@ public function getPathByAlias($alias, $langcode = NULL) { // language. If we used a language different from the one conveyed by the // requested URL, we might end up being unable to check if there is a path // alias matching the URL path. - $langcode = $langcode ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->id; + $langcode = $langcode ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(); // If we already know that there are no paths for this alias simply return. if (empty($alias) || !empty($this->noPath[$langcode][$alias])) { @@ -192,7 +191,7 @@ public function getAliasByPath($path, $langcode = NULL) { // language. If we used a language different from the one conveyed by the // requested URL, we might end up being unable to check if there is a path // alias matching the URL path. - $langcode = $langcode ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->id; + $langcode = $langcode ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(); // Check the path whitelist, if the top-level part before the first / // is not in the list, then there is no need to do anything further, diff --git a/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php b/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php index 1c709a1..67226ab 100644 --- a/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php +++ b/core/lib/Drupal/Core/PathProcessor/PathProcessorAlias.php @@ -45,7 +45,7 @@ public function processInbound($path, Request $request) { */ public function processOutbound($path, &$options = array(), Request $request = NULL) { if (empty($options['alias'])) { - $langcode = isset($options['language']) ? $options['language']->id : NULL; + $langcode = isset($options['language']) ? $options['language']->getId() : NULL; $path = $this->aliasManager->getAliasByPath($path, $langcode); } return $path; diff --git a/core/lib/Drupal/Core/Session/UserSession.php b/core/lib/Drupal/Core/Session/UserSession.php index da4f26d..a449d14 100644 --- a/core/lib/Drupal/Core/Session/UserSession.php +++ b/core/lib/Drupal/Core/Session/UserSession.php @@ -193,10 +193,10 @@ public function isAnonymous() { function getPreferredLangcode($default = NULL) { $language_list = language_list(); if (!empty($this->preferred_langcode) && isset($language_list[$this->preferred_langcode])) { - return $language_list[$this->preferred_langcode]->id; + return $language_list[$this->preferred_langcode]->getId(); } else { - return $default ? $default : language_default()->id; + return $default ? $default : language_default()->getId(); } } @@ -206,10 +206,10 @@ function getPreferredLangcode($default = NULL) { function getPreferredAdminLangcode($default = NULL) { $language_list = language_list(); if (!empty($this->preferred_admin_langcode) && isset($language_list[$this->preferred_admin_langcode])) { - return $language_list[$this->preferred_admin_langcode]->id; + return $language_list[$this->preferred_admin_langcode]->getId(); } else { - return $default ? $default : language_default()->id; + return $default ? $default : language_default()->getId(); } } diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php index 23deb8c..4f33f68 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php @@ -60,7 +60,7 @@ class TranslationManager implements TranslationInterface, TranslatorInterface { */ public function __construct(LanguageManagerInterface $language_manager) { $this->languageManager = $language_manager; - $this->defaultLangcode = $language_manager->getDefaultLanguage()->id; + $this->defaultLangcode = $language_manager->getDefaultLanguage()->getId(); } /** diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php index 3a0780f..aa25cc6 100644 --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php @@ -56,7 +56,7 @@ public function getValue() { public function setValue($value, $notify = TRUE) { // Support passing language objects. if (is_object($value)) { - $this->id = $value->id; + $this->id = $value->getId(); $this->language = $value; } elseif (isset($value) && !is_scalar($value)) { @@ -77,7 +77,7 @@ public function setValue($value, $notify = TRUE) { */ public function getString() { $language = $this->getValue(); - return $language ? $language->name : ''; + return $language ? $language->getName() : ''; } /** @@ -88,7 +88,7 @@ public function id() { return $this->id; } elseif (isset($this->language)) { - return $this->language->id; + return $this->language->getId(); } } diff --git a/core/lib/Drupal/Core/TypedData/TranslatableInterface.php b/core/lib/Drupal/Core/TypedData/TranslatableInterface.php index 999bfb7..91209a5 100644 --- 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); diff --git a/core/lib/Drupal/Core/Utility/LinkGenerator.php b/core/lib/Drupal/Core/Utility/LinkGenerator.php index b547d95..2c38b45 100644 --- a/core/lib/Drupal/Core/Utility/LinkGenerator.php +++ b/core/lib/Drupal/Core/Utility/LinkGenerator.php @@ -81,7 +81,7 @@ public function generateFromUrl($text, Url $url) { // Add a hreflang attribute if we know the language of this link's url and // hreflang has not already been set. if (!empty($variables['options']['language']) && !isset($variables['options']['attributes']['hreflang'])) { - $variables['options']['attributes']['hreflang'] = $variables['options']['language']->id; + $variables['options']['attributes']['hreflang'] = $variables['options']['language']->getId(); } // Set the "active" class if the 'set_active_class' option is not empty. diff --git a/core/lib/Drupal/Core/Utility/Token.php b/core/lib/Drupal/Core/Utility/Token.php index d03d645..73376e1 100644 --- a/core/lib/Drupal/Core/Utility/Token.php +++ b/core/lib/Drupal/Core/Utility/Token.php @@ -311,7 +311,7 @@ public function findWithPrefix(array $tokens, $prefix, $delimiter = ':') { */ public function getInfo() { if (is_null($this->tokenInfo)) { - $cache_id = 'token_info:' . $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id; + $cache_id = 'token_info:' . $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); $cache = $this->cache->get($cache_id); if ($cache) { $this->tokenInfo = $cache->data; diff --git a/core/lib/Drupal/Core/Validation/DrupalTranslator.php b/core/lib/Drupal/Core/Validation/DrupalTranslator.php index 01302ce..84847a5 100644 --- a/core/lib/Drupal/Core/Validation/DrupalTranslator.php +++ b/core/lib/Drupal/Core/Validation/DrupalTranslator.php @@ -55,7 +55,7 @@ public function setLocale($locale) { * Implements \Symfony\Component\Translation\TranslatorInterface::getLocale(). */ public function getLocale() { - return $this->locale ? $this->locale : \Drupal::languageManager()->getCurrentLanguage()->id; + return $this->locale ? $this->locale : \Drupal::languageManager()->getCurrentLanguage()->getId(); } /** diff --git a/core/modules/aggregator/aggregator.install b/core/modules/aggregator/aggregator.install index 2b755e1..0e2548d 100644 --- a/core/modules/aggregator/aggregator.install +++ b/core/modules/aggregator/aggregator.install @@ -4,7 +4,6 @@ * @file * Install, update and uninstall functions for the aggregator module. */ -use Drupal\Core\Language\Language; /** * Implements hook_requirements(). diff --git a/core/modules/aggregator/src/FeedForm.php b/core/modules/aggregator/src/FeedForm.php index e832d87..949d2d6 100644 --- a/core/modules/aggregator/src/FeedForm.php +++ b/core/modules/aggregator/src/FeedForm.php @@ -30,7 +30,7 @@ public function form(array $form, array &$form_state) { $form['langcode'] = array( '#title' => $this->t('Language'), '#type' => 'language_select', - '#default_value' => $feed->language()->id, + '#default_value' => $feed->language()->getId(), '#languages' => LanguageInterface::STATE_ALL, '#weight' => -4, ); diff --git a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php index 058ba18..13de3e0 100644 --- a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php +++ b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php @@ -190,7 +190,7 @@ public function process(FeedInterface $feed) { $entry = reset($entry); } else { - $entry = entity_create('aggregator_item', array('langcode' => $feed->language()->id)); + $entry = entity_create('aggregator_item', array('langcode' => $feed->language()->getId())); } if ($item['timestamp']) { $entry->setPostedTime($item['timestamp']); diff --git a/core/modules/aggregator/src/Tests/FeedLanguageTest.php b/core/modules/aggregator/src/Tests/FeedLanguageTest.php index d297abc..29a1863 100644 --- a/core/modules/aggregator/src/Tests/FeedLanguageTest.php +++ b/core/modules/aggregator/src/Tests/FeedLanguageTest.php @@ -24,7 +24,7 @@ class FeedLanguageTest extends AggregatorTestBase { /** * List of langcodes. * - * @var array + * @var \Drupal\Core\Language\LanguageInterface[] */ protected $langcodes = array(); @@ -55,14 +55,15 @@ public function setUp() { * Tests creation of feeds with a language. */ public function testFeedLanguage() { + /** @var \Drupal\aggregator\FeedInterface[] $feeds */ $feeds = array(); // Create feeds. - $feeds[1] = $this->createFeed(NULL, array('langcode' => $this->langcodes[1]->id)); - $feeds[2] = $this->createFeed(NULL, array('langcode' => $this->langcodes[2]->id)); + $feeds[1] = $this->createFeed(NULL, array('langcode' => $this->langcodes[1]->getId())); + $feeds[2] = $this->createFeed(NULL, array('langcode' => $this->langcodes[2]->getId())); // Make sure that the language has been assigned. - $this->assertEqual($feeds[1]->language()->id, $this->langcodes[1]->id); - $this->assertEqual($feeds[2]->language()->id, $this->langcodes[2]->id); + $this->assertEqual($feeds[1]->language()->getId(), $this->langcodes[1]->getId()); + $this->assertEqual($feeds[2]->language()->getId(), $this->langcodes[2]->getId()); // Create example nodes to create feed items from and then update the feeds. $this->createSampleNodes(); @@ -71,10 +72,11 @@ public function testFeedLanguage() { // Loop over the created feed items and verify that their language matches // the one from the feed. foreach ($feeds as $feed) { + /** @var \Drupal\aggregator\ItemInterface[] $items */ $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()->id, $feed->language()->id); + $this->assertEqual($item->language()->getId(), $feed->language()->getId()); } } } diff --git a/core/modules/block/block.install b/core/modules/block/block.install index a53a120..0d1ca69 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -5,8 +5,6 @@ * Install, update and uninstall functions for the block module. */ -use Drupal\Core\Language\Language; - /** * Implements hook_install(). */ diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 8c40c49..7f0bc9a 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -429,8 +429,8 @@ function block_language_entity_delete(Language $language) { // Remove the block visibility settings for the deleted language. foreach (entity_load_multiple('block') as $block) { $visibility = $block->get('visibility'); - if (isset($visibility['language']['langcodes'][$language->id()])) { - unset($visibility['language']['langcodes'][$language->id()]); + 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/src/BlockAccessController.php b/core/modules/block/src/BlockAccessController.php index 3bd9fb3..06b6269 100644 --- a/core/modules/block/src/BlockAccessController.php +++ b/core/modules/block/src/BlockAccessController.php @@ -110,7 +110,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'][\Drupal::languageManager()->getCurrentLanguage($visibility['language']['language_type'])->id])) { + if (empty($visibility['language']['langcodes'][\Drupal::languageManager()->getCurrentLanguage($visibility['language']['language_type'])->getId()])) { return FALSE; } } diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 9631404..63abb7f 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -160,9 +160,9 @@ public function form(array $form, array &$form_state) { $languages = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL); $langcodes_options = array(); foreach ($languages as $language) { - // @todo $language->name is not wrapped with t(), it should be replaced + // @todo $language->getName() 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', diff --git a/core/modules/block/src/Tests/BlockStorageUnitTest.php b/core/modules/block/src/Tests/BlockStorageUnitTest.php index 65d67f6..48f5a18 100644 --- a/core/modules/block/src/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/src/Tests/BlockStorageUnitTest.php @@ -93,7 +93,7 @@ protected function createTests() { 'id' => 'test_block', 'weight' => NULL, 'status' => TRUE, - 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id, + 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(), 'dependencies' => array('module' => array('block_test'), 'theme' => array('stark')), 'theme' => 'stark', 'region' => '-1', diff --git a/core/modules/block_content/src/BlockContentForm.php b/core/modules/block_content/src/BlockContentForm.php index e350ef5..755b7e8 100644 --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -102,14 +102,14 @@ public function form(array $form, array &$form_state) { // Set the correct default language. if ($block->isNew()) { $language_default = $this->languageManager->getCurrentLanguage($language_configuration['langcode']); - $block->langcode->value = $language_default->id; + $block->langcode->value = $language_default->getId(); } } $form['langcode'] = array( '#title' => $this->t('Language'), '#type' => 'language_select', - '#default_value' => $block->getUntranslated()->language()->id, + '#default_value' => $block->getUntranslated()->language()->getId(), '#languages' => LanguageInterface::STATE_ALL, '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], ); diff --git a/core/modules/block_content/src/Tests/BlockContentTypeTest.php b/core/modules/block_content/src/Tests/BlockContentTypeTest.php index fc20f0c..8ca2cf7 100644 --- a/core/modules/block_content/src/Tests/BlockContentTypeTest.php +++ b/core/modules/block_content/src/Tests/BlockContentTypeTest.php @@ -66,7 +66,7 @@ public function testBlockContentTypeCreation() { $this->assertTrue($block_type, 'The new block type has been created.'); // Check that the block type was created in site default language. - $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id; + $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); $this->assertEqual($block_type->langcode, $default_langcode); } diff --git a/core/modules/book/book.module b/core/modules/book/book.module index ad4b4d0..2154732 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -486,13 +486,13 @@ function template_preprocess_book_export_html(&$variables) { $variables['title'] = String::checkPlain($variables['title']); $variables['base_url'] = $base_url; $variables['language'] = $language_interface; - $variables['language_rtl'] = ($language_interface->direction == LanguageInterface::DIRECTION_RTL); + $variables['language_rtl'] = ($language_interface->getDirection() == LanguageInterface::DIRECTION_RTL); $variables['head'] = drupal_get_html_head(); // HTML element attributes. $attributes = array(); - $attributes['lang'] = $language_interface->id; - $attributes['dir'] = $language_interface->direction ? 'rtl' : 'ltr'; + $attributes['lang'] = $language_interface->getId(); + $attributes['dir'] = $language_interface->getDirection() ? 'rtl' : 'ltr'; $variables['html_attributes'] = new Attribute($attributes); } diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php index c491cf4..84a43d2 100644 --- a/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -465,7 +465,7 @@ public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL) { $nid = isset($link['nid']) ? $link['nid'] : 0; // Generate a cache ID (cid) specific for this $bid, $link, $language, and // depth. - $cid = 'book-links:' . $bid . ':all:' . $nid . ':' . $language_interface->id . ':' . (int) $max_depth; + $cid = 'book-links:' . $bid . ':all:' . $nid . ':' . $language_interface->getId() . ':' . (int) $max_depth; if (!isset($tree[$cid])) { // If the tree data was not in the static cache, build $tree_parameters. @@ -618,7 +618,7 @@ protected function doBookTreeBuild($bid, array $parameters = array()) { if (isset($parameters['expanded'])) { sort($parameters['expanded']); } - $tree_cid = 'book-links:' . $bid . ':tree-data:' . $language_interface->id . ':' . hash('sha256', serialize($parameters)); + $tree_cid = 'book-links:' . $bid . ':tree-data:' . $language_interface->getId() . ':' . hash('sha256', serialize($parameters)); // If we do not have this tree in the static cache, check {cache_data}. if (!isset($trees[$tree_cid])) { diff --git a/core/modules/ckeditor/ckeditor.admin.inc b/core/modules/ckeditor/ckeditor.admin.inc index 09a07a8..a4b779d 100644 --- a/core/modules/ckeditor/ckeditor.admin.inc +++ b/core/modules/ckeditor/ckeditor.admin.inc @@ -20,7 +20,7 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) { // Simplify the language direction information for toolbar buttons. $language_interface = \Drupal::languageManager()->getCurrentLanguage(); - $language_direction = $language_interface->direction ? 'rtl' : 'ltr'; + $language_direction = $language_interface->getDirection() ? 'rtl' : 'ltr'; // Create lists of active and disabled buttons. $editor = $variables['editor']; diff --git a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php index e130737..8f5642a 100644 --- a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php +++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php @@ -270,8 +270,8 @@ public function getJSSettings(EditorEntity $editor) { // Map the interface language code to a CKEditor translation. $ckeditor_langcodes = $this->getLangcodes(); $language_interface = $this->languageManager->getCurrentLanguage(); - if (isset($ckeditor_langcodes[$language_interface->id])) { - $display_langcode = $ckeditor_langcodes[$language_interface->id]; + if (isset($ckeditor_langcodes[$language_interface->getId()])) { + $display_langcode = $ckeditor_langcodes[$language_interface->getId()]; } // Next, set the most fundamental CKEditor settings. diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index b804aaa..123e15c 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -64,7 +64,7 @@ protected function init(array &$form_state) { // set. if ($comment->isNew()) { $language_content = \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT); - $comment->langcode->value = $language_content->id; + $comment->langcode->value = $language_content->getId(); } parent::init($form_state); diff --git a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php index ec76fb4..13863f3 100644 --- a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php @@ -63,8 +63,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->getCreatedTime(), 2, $language_interface->id); - $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->getChangedTime(), 2, $language_interface->id); + $tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->getCreatedTime(), 2, $language_interface->getId()); + $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->getChangedTime(), 2, $language_interface->getId()); $tests['[comment:parent:cid]'] = $comment->hasParentComment() ? $comment->getParentComment()->id() : NULL; $tests['[comment:parent:title]'] = String::checkPlain($parent_comment->getSubject()); $tests['[comment:node:nid]'] = $comment->getCommentedEntityId(); @@ -76,7 +76,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->id)); + $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId())); $this->assertEqual($output, $expected, format_string('Sanitized comment token %token replaced.', array('%token' => $input))); } @@ -93,7 +93,7 @@ function testCommentTokenReplacement() { $tests['[comment:author:name]'] = $this->admin_user->getUsername(); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->id, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input))); } @@ -108,7 +108,7 @@ function testCommentTokenReplacement() { $tests['[node:comment-count]'] = 2; foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('entity' => $node, 'node' => $node), array('langcode' => $language_interface->id)); + $output = $token_service->replace($input, array('entity' => $node, 'node' => $node), array('langcode' => $language_interface->getId())); $this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/config/src/Tests/ConfigEntityTest.php b/core/modules/config/src/Tests/ConfigEntityTest.php index fc079f4..ba1bffe 100644 --- a/core/modules/config/src/Tests/ConfigEntityTest.php +++ b/core/modules/config/src/Tests/ConfigEntityTest.php @@ -43,7 +43,7 @@ public static function getInfo() { * Tests CRUD operations. */ function testCRUD() { - $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id; + $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); // Verify default properties on a newly created empty entity. $empty = entity_create('config_test'); $this->assertIdentical($empty->id, NULL); diff --git a/core/modules/config/src/Tests/ConfigImportUITest.php b/core/modules/config/src/Tests/ConfigImportUITest.php index b95a666..88c4a13 100644 --- a/core/modules/config/src/Tests/ConfigImportUITest.php +++ b/core/modules/config/src/Tests/ConfigImportUITest.php @@ -63,7 +63,7 @@ function testImport() { 'test_dependencies' => array(), 'status' => TRUE, 'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651', - 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id, + 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(), 'dependencies' => array(), 'protected_property' => '', ); diff --git a/core/modules/config/src/Tests/ConfigImporterTest.php b/core/modules/config/src/Tests/ConfigImporterTest.php index 21ce402..07f4da4 100644 --- a/core/modules/config/src/Tests/ConfigImporterTest.php +++ b/core/modules/config/src/Tests/ConfigImporterTest.php @@ -177,7 +177,7 @@ function testNew() { 'test_dependencies' => array(), 'status' => TRUE, 'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651', - 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id, + 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(), 'dependencies' => array(), 'protected_property' => '', ); diff --git a/core/modules/config/src/Tests/ConfigLanguageOverrideWebTest.php b/core/modules/config/src/Tests/ConfigLanguageOverrideWebTest.php index 34f5172..5ac458a 100644 --- a/core/modules/config/src/Tests/ConfigLanguageOverrideWebTest.php +++ b/core/modules/config/src/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.'); diff --git a/core/modules/config/src/Tests/ConfigOverridesPriorityTest.php b/core/modules/config/src/Tests/ConfigOverridesPriorityTest.php index 6deab96..d294514 100644 --- a/core/modules/config/src/Tests/ConfigOverridesPriorityTest.php +++ b/core/modules/config/src/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(); diff --git a/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php b/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php index 10c5f25..da2d2bc 100644 --- a/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php +++ b/core/modules/config_translation/src/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; } diff --git a/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php b/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php index 529bc4a..1fa9e8d 100644 --- a/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php +++ b/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php @@ -69,7 +69,7 @@ public function access(Route $route, Request $request, AccountInterface $account $account->hasPermission('translate configuration') && $mapper->hasSchema() && $mapper->hasTranslatable() && - !$this->sourceLanguage->locked; + !$this->sourceLanguage->isLocked(); return $access ? static::ALLOW : static::DENY; } diff --git a/core/modules/config_translation/src/Controller/ConfigTranslationController.php b/core/modules/config_translation/src/Controller/ConfigTranslationController.php index 827b99e..f7d4f14 100644 --- a/core/modules/config_translation/src/Controller/ConfigTranslationController.php +++ b/core/modules/config_translation/src/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. diff --git a/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php b/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php index 9556be2..b7806d2 100644 --- a/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php +++ b/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php @@ -28,7 +28,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU $form = parent::buildForm($form, $form_state, $request, $plugin_id, $langcode); $form['#title'] = $this->t('Add @language translation for %label', array( '%label' => $this->mapper->getTitle(), - '@language' => $this->language->name, + '@language' => $this->language->getName(), )); return $form; } @@ -38,7 +38,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU */ public function submitForm(array &$form, array &$form_state) { parent::submitForm($form, $form_state); - drupal_set_message($this->t('Successfully saved @language translation.', array('@language' => $this->language->name))); + drupal_set_message($this->t('Successfully saved @language translation.', array('@language' => $this->language->getName()))); } } diff --git a/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php b/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php index a9a0a83..bf9bf40 100644 --- a/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php +++ b/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php @@ -88,7 +88,7 @@ public static function create(ContainerInterface $container) { * {@inheritdoc} */ public function getQuestion() { - return $this->t('Are you sure you want to delete the @language translation of %label?', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->name)); + return $this->t('Are you sure you want to delete the @language translation of %label?', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->getName())); } /** @@ -135,7 +135,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. @@ -144,7 +144,7 @@ public function submitForm(array &$form, array &$form_state) { $cache_backend->deleteAll(); } - drupal_set_message($this->t('@language translation of %label was deleted', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->name))); + drupal_set_message($this->t('@language translation of %label was deleted', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->getName()))); $form_state['redirect_route'] = $this->getCancelRoute(); } diff --git a/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php b/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php index 565d07a..23c5a71 100644 --- a/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php +++ b/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php @@ -28,7 +28,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU $form = parent::buildForm($form, $form_state, $request, $plugin_id, $langcode); $form['#title'] = $this->t('Edit @language translation for %label', array( '%label' => $this->mapper->getTitle(), - '@language' => $this->language->name, + '@language' => $this->language->getName(), )); return $form; } @@ -38,7 +38,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU */ public function submitForm(array &$form, array &$form_state) { parent::submitForm($form, $form_state); - drupal_set_message($this->t('Successfully updated @language translation.', array('@language' => $this->language->name))); + drupal_set_message($this->t('Successfully updated @language translation.', array('@language' => $this->language->getName()))); } } diff --git a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php index a57b60b..c2905ef 100644 --- a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php +++ b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php @@ -225,7 +225,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 = $config_factory->get($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)); @@ -325,12 +325,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', @@ -389,7 +389,7 @@ protected function setConfig(LanguageInterface $language, Config $base_config, L // 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. diff --git a/core/modules/config_translation/src/FormElement/DateFormat.php b/core/modules/config_translation/src/FormElement/DateFormat.php index d82d427..e4e897b 100644 --- a/core/modules/config_translation/src/FormElement/DateFormat.php +++ b/core/modules/config_translation/src/FormElement/DateFormat.php @@ -27,10 +27,10 @@ public function getFormElement(array $definition, LanguageInterface $language, $ $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', diff --git a/core/modules/config_translation/src/FormElement/Textarea.php b/core/modules/config_translation/src/FormElement/Textarea.php index 63aecf3..5f20e5c 100644 --- a/core/modules/config_translation/src/FormElement/Textarea.php +++ b/core/modules/config_translation/src/FormElement/Textarea.php @@ -28,9 +28,9 @@ public function getFormElement(array $definition, LanguageInterface $language, $ 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()), ); } diff --git a/core/modules/config_translation/src/FormElement/Textfield.php b/core/modules/config_translation/src/FormElement/Textfield.php index 44105ba..5905a7e 100644 --- a/core/modules/config_translation/src/FormElement/Textfield.php +++ b/core/modules/config_translation/src/FormElement/Textfield.php @@ -23,8 +23,8 @@ public function getFormElement(array $definition, LanguageInterface $language, $ 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()), ); } diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php index 08e28e3..b56e00b 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php @@ -331,7 +331,7 @@ public function testContactConfigEntityTranslation() { // Test that delete links work and operations perform properly. foreach ($this->langcodes as $langcode) { - $replacements = array('%label' => t('!label !entity_type', array('!label' => $label, '!entity_type' => Unicode::strtolower(t('Contact category')))), '@language' => language_load($langcode)->name); + $replacements = array('%label' => t('!label !entity_type', array('!label' => $label, '!entity_type' => Unicode::strtolower(t('Contact category')))), '@language' => language_load($langcode)->getName()); $this->drupalGet("$translation_base_url/$langcode/delete"); $this->assertRaw(t('Are you sure you want to delete the @language translation of %label?', $replacements)); diff --git a/core/modules/contact/contact.install b/core/modules/contact/contact.install index 477f359..5fc97bc 100644 --- a/core/modules/contact/contact.install +++ b/core/modules/contact/contact.install @@ -5,8 +5,6 @@ * Install, update and uninstall functions for the contact module. */ -use Drupal\Core\Language\Language; - /** * Implements hook_install(). */ diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 812c6df..dbd52db 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -138,14 +138,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; @@ -164,7 +164,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 emails, 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; } diff --git a/core/modules/contact/src/MessageForm.php b/core/modules/contact/src/MessageForm.php index 5915fd0..987be18 100644 --- a/core/modules/contact/src/MessageForm.php +++ b/core/modules/contact/src/MessageForm.php @@ -199,7 +199,7 @@ public function save(array $form, array &$form_state) { $params['contact_category'] = $category; $to = implode(', ', $category->recipients); - $recipient_langcode = language_default()->id; + $recipient_langcode = language_default()->getId(); } elseif ($recipient = $message->getPersonalRecipient()) { // Send to the user in the user's preferred language. @@ -217,14 +217,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->getEmail(), $language_interface->id, $params, $sender->getEmail()); + drupal_mail('contact', $key_prefix . '_copy', $sender->getEmail(), $language_interface->getId(), $params, $sender->getEmail()); } // 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->getEmail(), $language_interface->id, $params); + drupal_mail('contact', 'page_autoreply', $sender->getEmail(), $language_interface->getId(), $params); } $config = $this->config('contact.settings'); diff --git a/core/modules/contact/src/Tests/ContactSitewideTest.php b/core/modules/contact/src/Tests/ContactSitewideTest.php index 17c3f3e..823ac3d 100644 --- a/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -124,7 +124,7 @@ function testSiteWideContact() { // Check that the category was created in site default language. $langcode = \Drupal::config('contact.category.' . $id)->get('langcode'); - $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id; + $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); $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 d2a3e1e..9f018e9 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -279,7 +279,7 @@ function content_translation_form_language_content_settings_validate(array $form $values = $bundle_settings['settings']['language']; if (empty($values['language_show']) && \Drupal::languageManager()->isLanguageLocked($values['langcode'])) { foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $language) { - $locked_languages[] = $language->name; + $locked_languages[] = $language->getName(); } form_set_error($name, $form_state, t('Translation is not supported if language is always one of: @locked_languages', array('@locked_languages' => implode(', ', $locked_languages)))); } diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 1023c17..d6503fb 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -710,7 +710,7 @@ function content_translation_entity_presave(EntityInterface $entity) { // @todo Avoid using request attributes once translation metadata become // regular fields. $attributes = \Drupal::request()->attributes; - \Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->id, $attributes->get('source_langcode')); + \Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $attributes->get('source_langcode')); } } @@ -792,7 +792,7 @@ function content_translation_language_configuration_element_validate($element, a $values = $form_state['values'][$key]; if (!$values['language_show'] && $values['content_translation'] && \Drupal::languageManager()->isLanguageLocked($values['langcode'])) { foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $language) { - $locked_languages[] = $language->name; + $locked_languages[] = $language->getName(); } // @todo Set the correct form element name as soon as the element parents // are correctly set. We should be using NestedArray::getValue() but for diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc index 9898678..5d43626 100644 --- a/core/modules/content_translation/content_translation.pages.inc +++ b/core/modules/content_translation/content_translation.pages.inc @@ -21,7 +21,7 @@ function content_translation_overview(EntityInterface $entity) { $controller = content_translation_controller($entity->getEntityTypeId()); $languages = \Drupal::languageManager()->getLanguages(); - $original = $entity->getUntranslated()->language()->id; + $original = $entity->getUntranslated()->language()->getId(); $translations = $entity->getTranslationLanguages(); $administrator = \Drupal::currentUser()->hasPermission('administer languages'); @@ -50,8 +50,8 @@ function content_translation_overview(EntityInterface $entity) { $show_source_column = !empty($additional_source_langcodes); 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; @@ -105,7 +105,7 @@ function content_translation_overview(EntityInterface $entity) { $source_name = t('n/a'); } else { - $source_name = isset($languages[$source]) ? $languages[$source]->name : t('n/a'); + $source_name = isset($languages[$source]) ? $languages[$source]->getName() : t('n/a'); if ($controller->getTranslationAccess($entity, 'delete')) { $links['delete'] = isset($delete_links->links[$langcode]['href']) ? $delete_links->links[$langcode] : array('href' => $delete_links, 'language' => $language); $links['delete']['title'] = t('Delete'); @@ -115,7 +115,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()->id; + $source = $entity->language()->getId(); if ($source != $langcode && $controller->getTranslationAccess($entity, 'create')) { if ($translatable) { @@ -173,7 +173,7 @@ function content_translation_overview(EntityInterface $entity) { function _content_translation_get_switch_links($path) { $links = \Drupal::languageManager()->getLanguageSwitchLinks(LanguageInterface::TYPE_CONTENT, $path); if (empty($links)) { - // If content language is set up to fall back to the interface language, + // If content language is set up to fall back to the interface language // then there will be no switch links for LanguageInterface::TYPE_CONTENT, // ergo we also need to use interface switch links. $links = \Drupal::languageManager()->getLanguageSwitchLinks(LanguageInterface::TYPE_INTERFACE, $path); @@ -204,7 +204,7 @@ function content_translation_add_page(EntityInterface $entity, LanguageInterface $target = !empty($target) ? $target : \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT); // @todo Exploit the upcoming hook_entity_prepare() when available. content_translation_prepare_translation($entity, $source, $target); - $form_state['langcode'] = $target->id; + $form_state['langcode'] = $target->getId(); $form_state['content_translation']['source'] = $source; $form_state['content_translation']['target'] = $target; $form_state['content_translation']['translation_form'] = !$entity->access('update'); @@ -228,7 +228,7 @@ function content_translation_add_page(EntityInterface $entity, LanguageInterface */ function content_translation_edit_page(EntityInterface $entity, LanguageInterface $language = NULL) { $language = !empty($language) ? $language : \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT); - $form_state['langcode'] = $language->id; + $form_state['langcode'] = $language->getId(); $form_state['content_translation']['translation_form'] = TRUE; return \Drupal::service('entity.form_builder')->getForm($entity, 'default', $form_state); } @@ -245,7 +245,7 @@ function content_translation_edit_page(EntityInterface $entity, LanguageInterfac */ function content_translation_prepare_translation(EntityInterface $entity, LanguageInterface $source, LanguageInterface $target) { if ($entity instanceof ContentEntityInterface) { - $source_translation = $entity->getTranslation($source->id); - $entity->addTranslation($target->id, $source_translation->toArray()); + $source_translation = $entity->getTranslation($source->getId()); + $entity->addTranslation($target->getId(), $source_translation->toArray()); } } diff --git a/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php b/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php index 137b52e..c6a4afa 100644 --- a/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php +++ b/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php @@ -71,19 +71,20 @@ public function access(Route $route, Request $request, AccountInterface $account case 'create': $source = language_load($source) ?: $entity->language(); $target = language_load($target) ?: \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT); - return ($source->id != $target->id - && isset($languages[$source->id]) - && isset($languages[$target->id]) - && !isset($translations[$target->id]) + return ($source->getId() != $target->getId() + && isset($languages[$source->getId()]) + && isset($languages[$target->getId()]) + && !isset($translations[$target->getId()]) && $controller->getTranslationAccess($entity, $operation)) ? static::ALLOW : static::DENY; case 'update': case 'delete': $language = language_load($language) ?: \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT); - return isset($languages[$language->id]) - && $language->id != $entity->getUntranslated()->language()->id - && isset($translations[$language->id]) + return isset($languages[$language->getId()]) + && $language->getId() != $entity->getUntranslated()->language()->getId() + && isset($translations[$language->getId()]) + && $controller->getTranslationAccess($entity, $operation) ? static::ALLOW : static::DENY; } diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index bd9a9c1..3cd1361 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -46,7 +46,7 @@ public function __construct(EntityTypeInterface $entity_type) { * {@inheritdoc} */ public function retranslate(EntityInterface $entity, $langcode = NULL) { - $updated_langcode = !empty($langcode) ? $langcode : $entity->language()->id; + $updated_langcode = !empty($langcode) ? $langcode : $entity->language()->getId(); $translations = $entity->getTranslationLanguages(); foreach ($translations as $langcode => $language) { $entity->translation[$langcode]['outdated'] = $langcode != $updated_langcode; @@ -73,7 +73,7 @@ public function getTranslationAccess(EntityInterface $entity, $op) { * {@inheritdoc} */ public function getSourceLangcode(array $form_state) { - return isset($form_state['content_translation']['source']) ? $form_state['content_translation']['source']->id : FALSE; + return isset($form_state['content_translation']['source']) ? $form_state['content_translation']['source']->getId() : FALSE; } /** @@ -82,7 +82,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->getUntranslated()->language()->id; + $entity_langcode = $entity->getUntranslated()->language()->getId(); $source_langcode = $this->getSourceLangcode($form_state); $new_translation = !empty($source_langcode); @@ -101,7 +101,7 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac $title = $this->entityFormTitle($entity); // When editing the original values display just the entity label. if ($form_langcode != $entity_langcode) { - $t_args = array('%language' => $languages[$form_langcode]->name, '%title' => $entity->label()); + $t_args = array('%language' => $languages[$form_langcode]->getName(), '%title' => $entity->label()); $title = empty($source_langcode) ? $title . ' [' . t('%language translation', $t_args) . ']' : t('Create %language translation of %title', $t_args); } $form['#title'] = $title; @@ -112,7 +112,7 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac if ($has_translations && $new_translation) { $form['source_langcode'] = array( '#type' => 'details', - '#title' => t('Source language: @language', array('@language' => $languages[$source_langcode]->name)), + '#title' => t('Source language: @language', array('@language' => $languages[$source_langcode]->getName())), '#tree' => TRUE, '#weight' => -100, '#multilingual' => TRUE, @@ -130,8 +130,8 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac ), ); foreach (language_list(LanguageInterface::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(LanguageInterface::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(); } } } @@ -434,7 +434,7 @@ public function entityFormSourceChange($form, &$form_state) { $path = $entity->getSystemPath('drupal:content-translation-overview'); $form_state['redirect'] = $path . '/add/' . $source . '/' . $form_controller->getFormLangcode($form_state); $languages = language_list(); - drupal_set_message(t('Source language set to: %language', array('%language' => $languages[$source]->name))); + drupal_set_message(t('Source language set to: %language', array('%language' => $languages[$source]->getName()))); } /** diff --git a/core/modules/content_translation/src/FieldTranslationSynchronizer.php b/core/modules/content_translation/src/FieldTranslationSynchronizer.php index 196512b..544d1b7 100644 --- a/core/modules/content_translation/src/FieldTranslationSynchronizer.php +++ b/core/modules/content_translation/src/FieldTranslationSynchronizer.php @@ -50,7 +50,7 @@ public function synchronizeFields(ContentEntityInterface $entity, $sync_langcode // If the entity language is being changed there is nothing to synchronize. $entity_type = $entity->getEntityTypeId(); $entity_unchanged = isset($entity->original) ? $entity->original : $this->entityManager->getStorage($entity_type)->loadUnchanged($entity->id()); - if ($entity->getUntranslated()->language()->id != $entity_unchanged->getUntranslated()->language()->id) { + if ($entity->getUntranslated()->language()->getId() != $entity_unchanged->getUntranslated()->language()->getId()) { return; } diff --git a/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php b/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php index 4100fdb..30e0450 100644 --- a/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php +++ b/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php @@ -56,7 +56,7 @@ public function getConfirmText() { * {@inheritdoc} */ public function getQuestion() { - return $this->t('Are you sure you want to delete the @language translation of %label?', array('@language' => $this->language->name, '%label' => $this->entity->label())); + return $this->t('Are you sure you want to delete the @language translation of %label?', array('@language' => $this->language->getName(), '%label' => $this->entity->label())); } /** @@ -71,14 +71,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); } diff --git a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php index b299b3f..ee616e6 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php @@ -103,7 +103,7 @@ protected function setupLanguages() { foreach ($this->langcodes as $langcode) { language_save(new Language(array('id' => $langcode))); } - array_unshift($this->langcodes, \Drupal::languageManager()->getDefaultLanguage()->id); + array_unshift($this->langcodes, \Drupal::languageManager()->getDefaultLanguage()->getId()); } /** diff --git a/core/modules/field/src/Entity/FieldInstanceConfig.php b/core/modules/field/src/Entity/FieldInstanceConfig.php index bf8e354..bb91753 100644 --- a/core/modules/field/src/Entity/FieldInstanceConfig.php +++ b/core/modules/field/src/Entity/FieldInstanceConfig.php @@ -615,7 +615,7 @@ public function isMultiple() { public function getDefaultValue(EntityInterface $entity) { if (!empty($this->default_value_function)) { $function = $this->default_value_function; - return $function($entity, $this->getField(), $this, $entity->language()->id); + return $function($entity, $this->getField(), $this, $entity->language()->getId()); } elseif (!empty($this->default_value)) { return $this->default_value; diff --git a/core/modules/field/src/Plugin/views/field/Field.php b/core/modules/field/src/Plugin/views/field/Field.php index d336db6..d0498c3 100644 --- a/core/modules/field/src/Plugin/views/field/Field.php +++ b/core/modules/field/src/Plugin/views/field/Field.php @@ -294,7 +294,7 @@ public function query($use_groupby = FALSE) { // LanguageInterface::LANGCODE_NOT_SPECIFIED in reality so allow it as // well. // @see this::field_langcode() - $default_langcode = language_default()->id; + $default_langcode = language_default()->getId(); $langcode = str_replace( array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'), array($this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT), $default_langcode), @@ -901,7 +901,7 @@ protected function addSelfTokens(&$tokens, $item) { */ function field_langcode(EntityInterface $entity) { if ($this->getFieldDefinition()->isTranslatable()) { - $default_langcode = language_default()->id; + $default_langcode = language_default()->getId(); $langcode = str_replace( array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'), array($this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT), $default_langcode), @@ -913,7 +913,7 @@ function field_langcode(EntityInterface $entity) { // no data for the selected language. FieldItemListInterface::view() does // this as well, but since the returned language code is used before // calling it, the fallback needs to happen explicitly. - $langcode = $this->entityManager->getTranslationFromContext($entity, $langcode)->language()->id; + $langcode = $this->entityManager->getTranslationFromContext($entity, $langcode)->language()->getId(); return $langcode; } diff --git a/core/modules/field/src/Tests/FieldUnitTestBase.php b/core/modules/field/src/Tests/FieldUnitTestBase.php index 2100833..0f064b4 100644 --- a/core/modules/field/src/Tests/FieldUnitTestBase.php +++ b/core/modules/field/src/Tests/FieldUnitTestBase.php @@ -144,7 +144,7 @@ function _generateTestFieldValues($cardinality) { * The array of expected values. * @param $langcode * (Optional) The language code for the values. Defaults to - * \Drupal\Core\Language\LanguageInterface::LANGCODE_NOT_SPECIFIED. + * Drupal\Core\Language\LanguageInterface::LANGCODE_NOT_SPECIFIED. * @param $column * (Optional) The name of the column to check. Defaults to 'value'. */ diff --git a/core/modules/field/src/Tests/TranslationTest.php b/core/modules/field/src/Tests/TranslationTest.php index 618d8a5..c986f49 100644 --- a/core/modules/field/src/Tests/TranslationTest.php +++ b/core/modules/field/src/Tests/TranslationTest.php @@ -174,7 +174,7 @@ function testTranslatableFieldSaveLoad() { // @todo Test every translation once the Entity Translation API allows for // multilingual defaults. - $langcode = $entity->language()->id; + $langcode = $entity->language()->getId(); $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/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index 45a0c0d..b0f3a6c 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -108,7 +108,7 @@ function field_test_entity_display_build_alter(&$output, $context) { } if (isset($output['test_field'])) { - $output['test_field'][] = array('#markup' => 'entity language is ' . $context['entity']->language()->id); + $output['test_field'][] = array('#markup' => 'entity language is ' . $context['entity']->language()->getId()); } } diff --git a/core/modules/file/src/Tests/FileTokenReplaceTest.php b/core/modules/file/src/Tests/FileTokenReplaceTest.php index 3198681..a61ce5e 100644 --- a/core/modules/file/src/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/src/Tests/FileTokenReplaceTest.php @@ -53,10 +53,10 @@ function testFileTokenReplacement() { $tests['[file:mime]'] = String::checkPlain($file->getMimeType()); $tests['[file:size]'] = format_size($file->getSize()); $tests['[file:url]'] = String::checkPlain(file_create_url($file->getFileUri())); - $tests['[file:created]'] = format_date($file->getCreatedTime(), 'medium', '', NULL, $language_interface->id); - $tests['[file:created:short]'] = format_date($file->getCreatedTime(), 'short', '', NULL, $language_interface->id); - $tests['[file:changed]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->id); - $tests['[file:changed:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->id); + $tests['[file:created]'] = format_date($file->getCreatedTime(), 'medium', '', NULL, $language_interface->getId()); + $tests['[file:created:short]'] = format_date($file->getCreatedTime(), 'short', '', NULL, $language_interface->getId()); + $tests['[file:changed]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->getId()); + $tests['[file:changed:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->getId()); $tests['[file:owner]'] = String::checkPlain(user_format_name($this->admin_user)); $tests['[file:owner:uid]'] = $file->getOwnerId(); @@ -64,7 +64,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->id)); + $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->getId())); $this->assertEqual($output, $expected, format_string('Sanitized file token %token replaced.', array('%token' => $input))); } @@ -75,7 +75,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->id, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->getId(), '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 e2b0907..59a2a0f 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -269,13 +269,13 @@ function filter_formats(AccountInterface $account = NULL) { // All available formats are cached for performance. if (!isset($formats['all'])) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); - if ($cache = \Drupal::cache()->get("filter_formats:{$language_interface->id}")) { + if ($cache = \Drupal::cache()->get("filter_formats:{$language_interface->getId()}")) { $formats['all'] = $cache->data; } else { $formats['all'] = \Drupal::entityManager()->getStorage('filter_format')->loadByProperties(array('status' => TRUE)); uasort($formats['all'], 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); - \Drupal::cache()->set("filter_formats:{$language_interface->id}", $formats['all'], Cache::PERMANENT, array('filter_formats' => TRUE)); + \Drupal::cache()->set("filter_formats:{$language_interface->getId()}", $formats['all'], Cache::PERMANENT, array('filter_formats' => TRUE)); } } diff --git a/core/modules/filter/src/Tests/FilterCrudTest.php b/core/modules/filter/src/Tests/FilterCrudTest.php index b592c5f..63f5287 100644 --- a/core/modules/filter/src/Tests/FilterCrudTest.php +++ b/core/modules/filter/src/Tests/FilterCrudTest.php @@ -84,7 +84,7 @@ function testTextFormatCrud() { */ function verifyTextFormat($format) { $t_args = array('%format' => $format->name); - $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id; + $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); // Verify the loaded filter has all properties. $filter_format = entity_load('filter_format', $format->format); diff --git a/core/modules/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php index 6217835..4063d8a 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -300,7 +300,7 @@ private function doAdminTests($user) { 'name' => 'Tags', 'description' => $description, 'vid' => 'tags', - 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id, + 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(), 'help' => $help, )); $vocabulary->save(); diff --git a/core/modules/forum/src/Tests/ForumUninstallTest.php b/core/modules/forum/src/Tests/ForumUninstallTest.php index 3b38876..d954bb8 100644 --- a/core/modules/forum/src/Tests/ForumUninstallTest.php +++ b/core/modules/forum/src/Tests/ForumUninstallTest.php @@ -43,7 +43,7 @@ function testForumUninstallWithField() { // Create a taxonomy term. $term = entity_create('taxonomy_term', array( 'name' => t('A term'), - 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id, + 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(), 'description' => '', 'parent' => array(0), 'vid' => 'forums', diff --git a/core/modules/hal/src/Normalizer/FieldNormalizer.php b/core/modules/hal/src/Normalizer/FieldNormalizer.php index 99a669c..d898815 100644 --- a/core/modules/hal/src/Normalizer/FieldNormalizer.php +++ b/core/modules/hal/src/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(); @@ -43,8 +45,8 @@ public function normalize($field, $format = NULL, array $context = array()) { // to the field item values. else { foreach ($entity->getTranslationLanguages() as $language) { - $context['langcode'] = $language->id; - $translation = $entity->getTranslation($language->id); + $context['langcode'] = $language->getId(); + $translation = $entity->getTranslation($language->getId()); $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/language/language.module b/core/modules/language/language.module index 8b1e705..5f59443 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -96,7 +96,7 @@ function language_help($route_name, Request $request) { * Use \Drupal\language\LanguageAccessController. */ function language_access_language_edit_or_delete($language) { - return !$language->locked && \Drupal::currentUser()->hasPermission('administer languages'); + return !empty($language->locked) && \Drupal::currentUser()->hasPermission('administer languages'); } /** @@ -167,7 +167,7 @@ function language_process_language_select($element) { 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,14 +208,14 @@ function language_element_info() { */ function language_configuration_element_default_options() { $language_options = array( - 'site_default' => t("Site's default language (!language)", array('!language' => \Drupal::languageManager()->getDefaultLanguage()->name)), + 'site_default' => t("Site's default language (!language)", array('!language' => \Drupal::languageManager()->getDefaultLanguage()->getName())), 'current_interface' => t('Current interface language'), 'authors_default' => t("Author's preferred language"), ); $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; @@ -388,11 +388,11 @@ function language_get_default_langcode($entity_type, $bundle) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); switch ($configuration['langcode']) { case 'site_default': - $default_value = \Drupal::languageManager()->getDefaultLanguage()->id; + $default_value = \Drupal::languageManager()->getDefaultLanguage()->getId(); break; case 'current_interface': - $default_value = $language_interface->id; + $default_value = $language_interface->getId(); break; case 'authors_default': @@ -402,7 +402,7 @@ function language_get_default_langcode($entity_type, $bundle) { $default_value = $language_code; } else { - $default_value = $language_interface->id; + $default_value = $language_interface->getId(); } break; } @@ -418,28 +418,28 @@ function language_get_default_langcode($entity_type, $bundle) { /** * 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(); // 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 = !empty($language->locked); - $language_entity->weight = isset($language->weight) ? $language->weight : 0; - $language_entity->setDefault(!empty($language->default)); + $language_entity->label = $language->getName(); + $language_entity->direction = $language->getDirection(); + $language_entity->locked = $language->isLocked(); + $language_entity->weight = $language->getWeight(); + $language_entity->setDefault($language->isDefault()); $language_entity->save(); - $t_args = array('%language' => $language->name, '%langcode' => $language->id); - if ($language->is_new) { + $t_args = array('%language' => $language->getName(), '%langcode' => $language->getId()); + if ($language_entity->isNew()) { // Install any available language configuration overrides for the language. \Drupal::service('language.config_factory_override')->installLanguageOverrides($language->getId()); watchdog('language', 'The %language (%langcode) language has been created.', $t_args); @@ -462,11 +462,11 @@ function language_save($language) { */ function language_delete($langcode) { $languages = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL); - if (isset($languages[$langcode]) && !$languages[$langcode]->locked) { + if(isset($languages[$langcode]) && !$languages[$langcode]->isLocked()) { $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(); @@ -480,7 +480,7 @@ function language_delete($langcode) { 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; } @@ -536,10 +536,10 @@ function language_negotiation_url_prefixes_update() { 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. } @@ -599,7 +599,7 @@ function language_language_entity_insert(LanguageEntity $language) { // Add language to the list of language domains. $domains = language_negotiation_url_domains(); - $domains[$language->id()] = ''; + $domains[$language->id] = ''; language_negotiation_url_domains_save($domains); } @@ -609,12 +609,12 @@ function language_language_entity_insert(LanguageEntity $language) { function language_language_entity_delete(LanguageEntity $language) { // Remove language from language prefix list. $prefixes = language_negotiation_url_prefixes(); - unset($prefixes[$language->id()]); + unset($prefixes[$language->id]); language_negotiation_url_prefixes_save($prefixes); // Remove language from language domain list. $domains = language_negotiation_url_domains(); - unset($domains[$language->id()]); + unset($domains[$language->id]); language_negotiation_url_domains_save($domains); } @@ -664,12 +664,12 @@ function language_form_system_regional_settings_alter(&$form, &$form_state) { $languages = \Drupal::languageManager()->getLanguages(); $default = \Drupal::languageManager()->getDefaultLanguage(); foreach ($languages as $key => $language) { - $language_options[$key] = $language->name; + $language_options[$key] = $language->getName(); } $form['locale']['site_default_language'] = array( '#type' => 'select', '#title' => t('Default language'), - '#default_value' => $default->id, + '#default_value' => $default->getId(), '#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, @@ -686,6 +686,6 @@ function language_form_system_regional_settings_alter(&$form, &$form_state) { function language_system_regional_settings_form_submit($form, &$form_state) { $languages = \Drupal::languageManager()->getLanguages(); $language = $languages[$form_state['values']['site_default_language']]; - $language->default = TRUE; + $language->setDefault(TRUE); language_save($language); } diff --git a/core/modules/language/src/Config/LanguageConfigFactoryOverride.php b/core/modules/language/src/Config/LanguageConfigFactoryOverride.php index 6c71478..fa4484b 100644 --- a/core/modules/language/src/Config/LanguageConfigFactoryOverride.php +++ b/core/modules/language/src/Config/LanguageConfigFactoryOverride.php @@ -114,7 +114,7 @@ public function getStorage($langcode) { * {@inheritdoc} */ public function getCacheSuffix() { - return $this->language ? $this->language->id : NULL; + return $this->language ? $this->language->getId() : NULL; } /** diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index 0d9c7c6..0a4fe2a 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -199,6 +199,7 @@ public function saveLanguageTypesConfiguration(array $values) { * {@inheritdoc} */ public function getCurrentLanguage($type = BaseLanguageInterface::TYPE_INTERFACE) { + if (!isset($this->negotiatedLanguages[$type])) { // Ensure we have a valid value for this language type. $this->negotiatedLanguages[$type] = $this->getDefaultLanguage(); @@ -275,7 +276,7 @@ public function getLanguages($flags = BaseLanguageInterface::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.'; @@ -288,17 +289,17 @@ public function getLanguages($flags = BaseLanguageInterface::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)); + $weight = max(array($weight, $this->languages[$langcode]->getWeight())); } // Add locked languages, they will be filtered later if needed. $this->languages += $this->getDefaultLockedLanguages($weight); // Sort the language list by weight then title. - Language::sort($this->languages); + uasort($this->languages, '\Drupal\Core\Language\Language::sort'); } return parent::getLanguages($flags); @@ -312,14 +313,14 @@ public function updateLockedLanguageWeights() { // Get maximum weight to update the system languages to keep them on bottom. foreach ($this->getLanguages(BaseLanguageInterface::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(BaseLanguageInterface::STATE_LOCKED); - $config_ids = array_map(function($language) { return 'language.entity.' . $language->id; }, $locked_languages); + $config_ids = array_map(function($language) { return 'language.entity.' . $language->getId(); }, $locked_languages); foreach ($this->configFactory->loadMultiple($config_ids) as $config) { // Update system languages weight. $max_weight++; diff --git a/core/modules/language/src/Entity/Language.php b/core/modules/language/src/Entity/Language.php index bdb3d78..5965728 100644 --- a/core/modules/language/src/Entity/Language.php +++ b/core/modules/language/src/Entity/Language.php @@ -87,9 +87,9 @@ class Language extends ConfigEntityBase implements LanguageInterface { * container using the language.default service in when the entity is saved. * The value is set correctly when a language entity is created or loaded. * - * @see \Drupal\language\Entity\Language::postSave() - * @see \Drupal\language\Entity\Language::isDefault() - * @see \Drupal\language\Entity\Language::setDefault() + * @see \Drupal\language\Entity\LanguageInterface::postSave() + * @see \Drupal\language\Entity\LanguageInterface::isDefault() + * @see \Drupal\language\Entity\LanguageInterface::setDefault() * * @var bool */ @@ -101,8 +101,8 @@ class Language extends ConfigEntityBase implements LanguageInterface { * This property is not saved to the language entity, but is needed for * detecting when to rebuild the services. * - * @see \Drupal\language\Entity\Language::preSave() - * @see \Drupal\language\Entity\Language::postSave() + * @see \Drupal\language\Entity\LanguageInterface::preSave() + * @see \Drupal\language\Entity\LanguageInterface::postSave() * * @var bool */ @@ -137,7 +137,7 @@ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); // Store whether or not the site is already multilingual so that we can // rebuild services if necessary during - // \Drupal\language\Entity\Language::postSave(). + // \Drupal\language\Entity\LanguageInterface::postSave(). $this->preSaveMultilingual = \Drupal::languageManager()->isMultilingual(); // Languages are picked from a predefined list which is given in English. // For the uncommon case of custom languages the label should be given in diff --git a/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php b/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php index fcc1ddf..0c3d825 100644 --- a/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php +++ b/core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php @@ -86,7 +86,7 @@ public function onKernelRequestLanguage(GetResponseEvent $event) { } // After the language manager has initialized, set the default langcode // for the string translations. - $langcode = $this->languageManager->getCurrentLanguage()->id; + $langcode = $this->languageManager->getCurrentLanguage()->getId(); $this->translation->setDefaultLangcode($langcode); } } diff --git a/core/modules/language/src/Form/LanguageAddForm.php b/core/modules/language/src/Form/LanguageAddForm.php index 3eb0bc6..1f74246 100644 --- a/core/modules/language/src/Form/LanguageAddForm.php +++ b/core/modules/language/src/Form/LanguageAddForm.php @@ -98,7 +98,7 @@ public function submitForm(array &$form, array &$form_state) { // Save the language and inform the user that it happened. $language = language_save($language); - drupal_set_message($this->t('The language %language has been created and can now be used.', array('%language' => $language->name))); + drupal_set_message($this->t('The language %language has been created and can now be used.', array('%language' => $language->getName()))); // Tell the user they have the option to add a language switcher block // to their theme so they can switch between the languages. @@ -124,7 +124,7 @@ public function validateCustom(array $form, array &$form_state) { $this->validateCommon($form['custom_language'], $form_state); if ($language = language_load($langcode)) { - $this->setFormError('langcode', $form_state, $this->t('The language %language (%langcode) already exists.', array('%language' => $language->name, '%langcode' => $langcode))); + $this->setFormError('langcode', $form_state, $this->t('The language %language (%langcode) already exists.', array('%language' => $language->getName(), '%langcode' => $langcode))); } } else { @@ -142,7 +142,7 @@ public function validatePredefined($form, &$form_state) { } else { if ($language = language_load($langcode)) { - $this->setFormError('predefined_langcode', $form_state, $this->t('The language %language (%langcode) already exists.', array('%language' => $language->name, '%langcode' => $langcode))); + $this->setFormError('predefined_langcode', $form_state, $this->t('The language %language (%langcode) already exists.', array('%language' => $language->getName(), '%langcode' => $langcode))); } } } diff --git a/core/modules/language/src/Form/LanguageDeleteForm.php b/core/modules/language/src/Form/LanguageDeleteForm.php index 1e1e2a0..a98ea37 100644 --- a/core/modules/language/src/Form/LanguageDeleteForm.php +++ b/core/modules/language/src/Form/LanguageDeleteForm.php @@ -88,7 +88,7 @@ public function buildForm(array $form, array &$form_state) { $langcode = $this->entity->id(); // Warn and redirect user when attempting to delete the default language. - if (language_default()->id == $langcode) { + if (language_default()->getId() == $langcode) { drupal_set_message($this->t('The default language cannot be deleted.')); $url = $this->urlGenerator->generateFromPath('admin/config/regional/language', array('absolute' => TRUE)); return new RedirectResponse($url); diff --git a/core/modules/language/src/Form/LanguageEditForm.php b/core/modules/language/src/Form/LanguageEditForm.php index 2dacdc2..9c69bb8 100644 --- a/core/modules/language/src/Form/LanguageEditForm.php +++ b/core/modules/language/src/Form/LanguageEditForm.php @@ -51,8 +51,8 @@ public function submitForm(array &$form, array &$form_state) { $languages = language_list(); $langcode = $form_state['values']['langcode']; $language = $languages[$langcode]; - $language->name = $form_state['values']['name']; - $language->direction = $form_state['values']['direction']; + $language->setName($form_state['values']['name']); + $language->setDirection($form_state['values']['direction']); language_save($language); $form_state['redirect_route']['route_name'] = 'language.admin_overview'; diff --git a/core/modules/language/src/Form/LanguageFormBase.php b/core/modules/language/src/Form/LanguageFormBase.php index 583787a..d451277 100644 --- a/core/modules/language/src/Form/LanguageFormBase.php +++ b/core/modules/language/src/Form/LanguageFormBase.php @@ -49,7 +49,7 @@ public static function create(ContainerInterface $container) { */ public function commonForm(array &$form) { $language = $this->entity; - if (isset($language->id)) { + if (!$language->isNew()) { $form['langcode_view'] = array( '#type' => 'item', '#title' => $this->t('Language code'), @@ -75,7 +75,7 @@ public function commonForm(array &$form) { '#type' => 'textfield', '#title' => $this->t('Language name in English'), '#maxlength' => 64, - '#default_value' => $language->label, + '#default_value' => $language->label(), '#required' => TRUE, ); $form['direction'] = array( diff --git a/core/modules/language/src/Form/NegotiationBrowserForm.php b/core/modules/language/src/Form/NegotiationBrowserForm.php index f82e54a..3dc4ad7 100644 --- a/core/modules/language/src/Form/NegotiationBrowserForm.php +++ b/core/modules/language/src/Form/NegotiationBrowserForm.php @@ -63,7 +63,7 @@ public function buildForm(array $form, array &$form_state) { $existing_languages = array(); foreach ($languages as $langcode => $language) { - $existing_languages[$langcode] = $language->name; + $existing_languages[$langcode] = $language->getName(); } // If we have no languages available, present the list of predefined languages diff --git a/core/modules/language/src/Form/NegotiationUrlForm.php b/core/modules/language/src/Form/NegotiationUrlForm.php index d8c2490..bfec4ac 100644 --- a/core/modules/language/src/Form/NegotiationUrlForm.php +++ b/core/modules/language/src/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))); } } diff --git a/core/modules/language/src/LanguageListBuilder.php b/core/modules/language/src/LanguageListBuilder.php index c5bd66a..36209c5 100644 --- a/core/modules/language/src/LanguageListBuilder.php +++ b/core/modules/language/src/LanguageListBuilder.php @@ -49,7 +49,7 @@ public function getDefaultOperations(EntityInterface $entity) { $default = language_default(); // Deleting the site default language is not allowed. - if ($entity->id() == $default->id) { + if ($entity->id() == $default->getId()) { unset($operations['delete']); } diff --git a/core/modules/language/src/LanguageNegotiationMethodBase.php b/core/modules/language/src/LanguageNegotiationMethodBase.php index 3f48f7a..8fc98e9 100644 --- a/core/modules/language/src/LanguageNegotiationMethodBase.php +++ b/core/modules/language/src/LanguageNegotiationMethodBase.php @@ -63,7 +63,7 @@ public function setCurrentUser(AccountInterface $current_user) { */ public function persist(BaseLanguageInterface $language) { // Remember the method ID used to detect the language. - $language->method_id = static::METHOD_ID; + $language->setNegotiationMethodId(static::METHOD_ID); } } diff --git a/core/modules/language/src/LanguageNegotiationMethodInterface.php b/core/modules/language/src/LanguageNegotiationMethodInterface.php index 1913d41..e4f47c9 100644 --- a/core/modules/language/src/LanguageNegotiationMethodInterface.php +++ b/core/modules/language/src/LanguageNegotiationMethodInterface.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Language\LanguageInterface as BaseLanguageInterface; +use Drupal\Core\Language\LanguageInterface as CoreLanguageInterface; use Drupal\Core\Session\AccountInterface; use Symfony\Component\HttpFoundation\Request; @@ -62,4 +63,5 @@ public function getLangcode(Request $request = NULL); */ public function persist(BaseLanguageInterface $language); + } diff --git a/core/modules/language/src/LanguageNegotiator.php b/core/modules/language/src/LanguageNegotiator.php index cdeb8cf..2533dff 100644 --- a/core/modules/language/src/LanguageNegotiator.php +++ b/core/modules/language/src/LanguageNegotiator.php @@ -159,7 +159,7 @@ public function initializeType($type) { if (!$language) { // If no other language was found use the default one. $language = $this->languageManager->getDefaultLanguage(); - $language->method_id = LanguageNegotiatorInterface::METHOD_ID; + $language->setNegotiationMethodId(LanguageNegotiatorInterface::METHOD_ID); } return $language; diff --git a/core/modules/language/src/LanguageNegotiatorInterface.php b/core/modules/language/src/LanguageNegotiatorInterface.php index 13d7068..e092dbc 100644 --- a/core/modules/language/src/LanguageNegotiatorInterface.php +++ b/core/modules/language/src/LanguageNegotiatorInterface.php @@ -91,7 +91,7 @@ * // If we are on an administrative path, override with the default * language. * if ($request->query->has('q') && strtok($request->query->get('q'), '/') == 'admin') { - * return $this->languageManager->getDefaultLanguage()->id; + * return $this->languageManager->getDefaultLanguage()->getId(); * } * return $langcode; * } diff --git a/core/modules/language/src/Plugin/Condition/Language.php b/core/modules/language/src/Plugin/Condition/Language.php index e6268c2..cc02c22 100644 --- a/core/modules/language/src/Plugin/Condition/Language.php +++ b/core/modules/language/src/Plugin/Condition/Language.php @@ -35,7 +35,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { $languages = language_list(LanguageInterface::STATE_ALL); $langcodes_options = array(); foreach ($languages as $language) { - $langcodes_options[$language->id] = $language->getName(); + $langcodes_options[$language->getId()] = $language->getName(); } $form['langcodes'] = array( '#type' => 'checkboxes', @@ -72,8 +72,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->id])) { - $result[$item->id] = $item->name; + if (!empty($selected[$item->getId()])) { + $result[$item->getId()] = $item->getName(); } return $result; }, array()); @@ -102,7 +102,7 @@ public function evaluate() { $language = $this->getContextValue('language'); // Language visibility settings. - return !empty($this->configuration['langcodes'][$language->id]); + return !empty($this->configuration['langcodes'][$language->getId()]); } /** diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php index 8cf294a..d20a187 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php @@ -73,7 +73,7 @@ public function persist(LanguageInterface $language) { // We need to update the session parameter with the request value only if we // have an authenticated user. - $langcode = $language->id; + $langcode = $language->getId(); if ($langcode && $this->languageManager) { $languages = $this->languageManager->getLanguages(); if ($this->currentUser->isAuthenticated() && isset($languages[$langcode])) { @@ -127,15 +127,15 @@ function getLanguageSwitchLinks(Request $request, $type, $path) { $links = array(); $config = $this->config->get('language.negotiation')->get('session'); $param = $config['parameter']; - $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : $this->languageManager->getCurrentLanguage($type)->id; + $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : $this->languageManager->getCurrentLanguage($type)->getId(); $query = array(); parse_str($request->getQueryString(), $query); foreach ($this->languageManager->getLanguages() as $language) { - $langcode = $language->id; + $langcode = $language->getId(); $links[$langcode] = array( 'href' => $path, - 'title' => $language->name, + 'title' => $language->getName(), 'attributes' => array('class' => array('language-link')), 'query' => $query, ); diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUI.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUI.php index a96dcbd..fd7eb75 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUI.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUI.php @@ -32,7 +32,7 @@ class LanguageNegotiationUI extends LanguageNegotiationMethodBase { * {@inheritdoc} */ public function getLangcode(Request $request = NULL) { - return $this->languageManager ? $this->languageManager->getCurrentLanguage()->id : NULL; + return $this->languageManager ? $this->languageManager->getCurrentLanguage()->getId() : NULL; } } diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php index 1cb5ccd..5ec8fe5 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php @@ -64,14 +64,14 @@ public function getLangcode(Request $request = NULL) { // Search prefix within added languages. $negotiated_language = FALSE; foreach ($languages as $language) { - if (isset($config['prefixes'][$language->id]) && $config['prefixes'][$language->id] == $prefix) { + if (isset($config['prefixes'][$language->getId()]) && $config['prefixes'][$language->getId()] == $prefix) { $negotiated_language = $language; break; } } if ($negotiated_language) { - $langcode = $negotiated_language->id; + $langcode = $negotiated_language->getId(); } break; @@ -80,13 +80,13 @@ public function getLangcode(Request $request = NULL) { $http_host = $request->getHost(); foreach ($languages as $language) { // Skip the check if the language doesn't have a domain. - if (!empty($config['domains'][$language->id])) { + if (!empty($config['domains'][$language->getId()])) { // Ensure that there is exactly one protocol in the URL when // checking the hostname. - $host = 'http://' . str_replace(array('http://', 'https://'), '', $config['domains'][$language->id]); + $host = 'http://' . str_replace(array('http://', 'https://'), '', $config['domains'][$language->getId()]); $host = parse_url($host, PHP_URL_HOST); if ($http_host == $host) { - $langcode = $language->id; + $langcode = $language->getId(); break; } } @@ -108,7 +108,7 @@ public function processInbound($path, Request $request) { // Search prefix within added languages. foreach ($this->languageManager->getLanguages() as $language) { - if (isset($config['prefixes'][$language->id]) && $config['prefixes'][$language->id] == $prefix) { + if (isset($config['prefixes'][$language->getId()]) && $config['prefixes'][$language->getId()] == $prefix) { // Rebuild $path with the language removed. $path = implode('/', $parts); break; @@ -135,17 +135,17 @@ public function processOutbound($path, &$options = array(), Request $request = N $options['language'] = $language_url; } // We allow only added languages here. - elseif (!is_object($options['language']) || !isset($languages[$options['language']->id])) { + elseif (!is_object($options['language']) || !isset($languages[$options['language']->getId()])) { return $path; } $config = $this->config->get('language.negotiation')->get('url'); if ($config['source'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) { - if (is_object($options['language']) && !empty($config['prefixes'][$options['language']->id])) { - return empty($path) ? $config['prefixes'][$options['language']->id] : $config['prefixes'][$options['language']->id] . '/' . $path; + if (is_object($options['language']) && !empty($config['prefixes'][$options['language']->getId()])) { + return empty($path) ? $config['prefixes'][$options['language']->getId()] : $config['prefixes'][$options['language']->getId()] . '/' . $path; } } elseif ($config['source'] == LanguageNegotiationUrl::CONFIG_DOMAIN) { - if (is_object($options['language']) && !empty($config['domains'][$options['language']->id])) { + if (is_object($options['language']) && !empty($config['domains'][$options['language']->getId()])) { // Save the original base URL. If it contains a port, we need to // retain it below. @@ -156,7 +156,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 . '://' . $config['domains'][$options['language']->id]; + $options['base_url'] = $url_scheme . '://' . $config['domains'][$options['language']->getId()]; // In case either the original base URL or the HTTP host contains a // port, retain it. @@ -191,9 +191,9 @@ function getLanguageSwitchLinks(Request $request, $type, $path) { $links = array(); foreach ($this->languageManager->getLanguages() as $language) { - $links[$language->id] = array( + $links[$language->getId()] = array( 'href' => $path, - 'title' => $language->name, + 'title' => $language->getName(), 'language' => $language, 'attributes' => array('class' => array('language-link')), ); diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php index 6f771e8..abaa6e3 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php @@ -62,11 +62,11 @@ public function getLangcode(Request $request = NULL) { // information, a missing URL language information indicates that URL // language should be the default one, otherwise we fall back to an // already detected language. - if (($prefix && empty($config['prefixes'][$default->id])) || (!$prefix && empty($config['domains'][$default->id]))) { - $langcode = $default->id; + if (($prefix && empty($config['prefixes'][$default->getId()])) || (!$prefix && empty($config['domains'][$default->getId()]))) { + $langcode = $default->getId(); } else { - $langcode = $this->languageManager->getCurrentLanguage()->id; + $langcode = $this->languageManager->getCurrentLanguage()->getId(); } } diff --git a/core/modules/language/src/Plugin/views/field/LanguageField.php b/core/modules/language/src/Plugin/views/field/LanguageField.php index 3909fcd..152104d 100644 --- a/core/modules/language/src/Plugin/views/field/LanguageField.php +++ b/core/modules/language/src/Plugin/views/field/LanguageField.php @@ -44,7 +44,7 @@ public function render(ResultRow $values) { // ready, see http://drupal.org/node/1616594. $value = $this->getValue($values); $language = language_load($value); - return $language ? $language->name : ''; + return $language ? $language->getName() : ''; } } diff --git a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php index c7c85f1..f9721a7 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php @@ -84,17 +84,17 @@ 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 = \Drupal::languageManager()->getCurrentLanguage(); - $this->assertEqual($langcode, $language_interface->id); + $this->assertEqual($langcode, $language_interface->getId()); // Site's default. $old_default = \Drupal::languageManager()->getDefaultLanguage(); // Ensure the language entity default value is correct. $language_entity = entity_load('language_entity', $old_default->getId()); $this->assertTrue($language_entity->get('default'), 'The en language entity is flagged as the default language.'); - $old_default->default = FALSE; + $old_default->setDefault(FALSE); language_save($old_default); $new_default = \Drupal::languageManager()->getLanguage('cc'); - $new_default->default = TRUE; + $new_default->setDefault(TRUE); language_save($new_default); language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'site_default', 'language_show' => TRUE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); @@ -104,7 +104,7 @@ public function testDefaultLangcode() { $language_entity = entity_load('language_entity', $old_default->getId()); $this->assertFalse($language_entity->get('default'), 'The en language entity is not flagged as the default language.'); $language_entity = entity_load('language_entity', 'cc'); - // Check calling the Drupal\language\Entity\Language::isDefault() method + // Check calling the Drupal\language\Entity\LanguageInterface::isDefault() method // directly. $this->assertTrue($language_entity->isDefault(), 'The cc language entity is flagged as the default language.'); diff --git a/core/modules/language/src/Tests/LanguageConfigurationTest.php b/core/modules/language/src/Tests/LanguageConfigurationTest.php index 3ca6528..8abcd83 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationTest.php @@ -160,8 +160,8 @@ protected function checkConfigurableLanguageWeight($state = 'by default') { $max_configurable_language_weight = $this->getHighestConfigurableLanguageWeight(); $replacements = array('@event' => $state); foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $locked_language) { - $replacements['%language'] = $locked_language->name; - $this->assertTrue($locked_language->weight > $max_configurable_language_weight, format_string('System language %language has higher weight than configurable languages @event', $replacements)); + $replacements['%language'] = $locked_language->getName(); + $this->assertTrue($locked_language->getWeight() > $max_configurable_language_weight, format_string('System language %language has higher weight than configurable languages @event', $replacements)); } } diff --git a/core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php b/core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php index bf48f58..15c28c1 100644 --- a/core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php +++ b/core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php @@ -49,7 +49,7 @@ public function testLanguageConfiguration() { $this->assertText(t('!name field is required.', array('!name' => t('Language code')))); $this->assertText(t('!name field is required.', array('!name' => t('Language name in English')))); $empty_language = new Language(); - $this->assertFieldChecked('edit-direction-' . $empty_language->direction, 'Consistent usage of language direction.'); + $this->assertFieldChecked('edit-direction-' . $empty_language->getDirection(), 'Consistent usage of language direction.'); $this->assertEqual($this->getUrl(), url('admin/config/regional/language/add', array('absolute' => TRUE)), 'Correct page redirection.'); // Test validation of invalid values. diff --git a/core/modules/language/src/Tests/LanguageDependencyInjectionTest.php b/core/modules/language/src/Tests/LanguageDependencyInjectionTest.php index 23ba560..a10d267 100644 --- a/core/modules/language/src/Tests/LanguageDependencyInjectionTest.php +++ b/core/modules/language/src/Tests/LanguageDependencyInjectionTest.php @@ -62,7 +62,7 @@ function testDependencyInjectedNewDefaultLanguage() { // The language system creates a Language object which contains the // same properties as the new default language object. $result = \Drupal::languageManager()->getCurrentLanguage(); - $this->assertIdentical($result->id, 'fr'); + $this->assertIdentical($result->getId(), 'fr'); // Delete the language to check that we fallback to the default. try { @@ -77,7 +77,7 @@ function testDependencyInjectedNewDefaultLanguage() { language_save($default_language); language_delete('fr'); $result = \Drupal::languageManager()->getCurrentLanguage(); - $this->assertIdentical($result->id, $default_language->id); + $this->assertIdentical($result->getId(), $default_language->getId()); } } diff --git a/core/modules/language/src/Tests/LanguageFallbackTest.php b/core/modules/language/src/Tests/LanguageFallbackTest.php index 335909b..b35fce9 100644 --- a/core/modules/language/src/Tests/LanguageFallbackTest.php +++ b/core/modules/language/src/Tests/LanguageFallbackTest.php @@ -31,8 +31,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); } } @@ -64,7 +64,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); diff --git a/core/modules/language/src/Tests/LanguagePathMonolingualTest.php b/core/modules/language/src/Tests/LanguagePathMonolingualTest.php index 73e5b85..7548b90 100644 --- a/core/modules/language/src/Tests/LanguagePathMonolingualTest.php +++ b/core/modules/language/src/Tests/LanguagePathMonolingualTest.php @@ -57,7 +57,7 @@ function setUp() { // Verify that French is the only language. $this->container->get('language_manager')->reset(); $this->assertFalse(\Drupal::languageManager()->isMultilingual(), 'Site is mono-lingual'); - $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->id, 'fr', 'French is the default language'); + $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), '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/src/Tests/LanguageUILanguageNegotiationTest.php b/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php index a3fe8e8..dcc0939 100644 --- a/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php @@ -397,7 +397,7 @@ function testUrlLanguageFallback() { // language. $args = array(':id' => 'block-test-language-block', ':url' => base_path() . $GLOBALS['script_path'] . $langcode_browser_fallback); $fields = $this->xpath('//div[@id=:id]//a[@class="language-link active" and starts-with(@href, :url)]', $args); - $this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->name, 'The browser language is the URL active language'); + $this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->getName(), 'The browser language is the URL active language'); // Check that URLs are rewritten using the given browser language. $fields = $this->xpath('//strong[@class="site-name"]/a[@rel="home" and @href=:url]', $args); diff --git a/core/modules/language/src/Tests/LanguageUrlRewritingTest.php b/core/modules/language/src/Tests/LanguageUrlRewritingTest.php index 1079031..2242c8d 100644 --- a/core/modules/language/src/Tests/LanguageUrlRewritingTest.php +++ b/core/modules/language/src/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; @@ -55,7 +56,7 @@ function setUp() { function testUrlRewritingEdgeCases() { // Check URL rewriting with a non-installed language. $non_existing = \Drupal::languageManager()->getDefaultLanguage(); - $non_existing->id = $this->randomName(); + $non_existing->setId($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'); // Check that URL rewriting is not applied to subrequests. @@ -70,14 +71,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)), '/'); @@ -88,7 +88,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; } diff --git a/core/modules/language/tests/language_test/language_test.module b/core/modules/language/tests/language_test/language_test.module index aaa34fd..c9a17c5 100644 --- a/core/modules/language/tests/language_test/language_test.module +++ b/core/modules/language/tests/language_test/language_test.module @@ -13,8 +13,8 @@ */ function language_test_page_build() { language_test_store_language_negotiation(); - if (isset(\Drupal::languageManager()->getCurrentLanguage()->id) && isset(\Drupal::languageManager()->getCurrentLanguage()->method_id)) { - drupal_set_message(t('Language negotiation method: @name', array('@name' => \Drupal::languageManager()->getCurrentLanguage()->method_id))); + if (\Drupal::languageManager()->getCurrentLanguage()->getId() && \Drupal::languageManager()->getCurrentLanguage()->getNegotiationMethodId()) { + drupal_set_message(t('Language negotiation method: @name', array('@name' => \Drupal::languageManager()->getCurrentLanguage()->getNegotiationMethodId()))); } } @@ -69,7 +69,7 @@ function language_test_store_language_negotiation() { if (\Drupal::moduleHandler()->moduleExists('language')) { $last = array(); foreach (\Drupal::languageManager()->getDefinedLanguageTypes() as $type) { - $last[$type] = \Drupal::languageManager()->getCurrentLanguage($type)->id; + $last[$type] = \Drupal::languageManager()->getCurrentLanguage($type)->getId(); } \Drupal::state()->set('language_test.language_negotiation_last', $last); } diff --git a/core/modules/language/tests/src/LanguageNegotiationUrlTest.php b/core/modules/language/tests/src/LanguageNegotiationUrlTest.php index 6a4df28..1926cd5 100644 --- a/core/modules/language/tests/src/LanguageNegotiationUrlTest.php +++ b/core/modules/language/tests/src/LanguageNegotiationUrlTest.php @@ -38,13 +38,17 @@ public static function getInfo() { public function setUp() { // Set up some languages to be used by the language-based path processor. + $language_de = $this->getMock('\Drupal\Core\Language\LanguageInterface'); + $language_de->expects($this->any()) + ->method('getId') + ->will($this->returnValue('de')); + $language_en = $this->getMock('\Drupal\Core\Language\LanguageInterface'); + $language_en->expects($this->any()) + ->method('getId') + ->will($this->returnValue('en')); $languages = array( - 'de' => (object) array( - 'id' => 'de', - ), - 'en' => (object) array( - 'id' => 'en', - ), + 'de' => $language_de, + 'en' => $language_en, ); // Create a language manager stub. diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index c62c842..9e1fe0a 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -5,7 +5,6 @@ * Install, update, and uninstall functions for the Locale module. */ -use Drupal\Core\Language\Language; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSelected; /** @@ -297,10 +296,10 @@ function locale_requirements($phase) { foreach ($status as $project) { foreach ($project as $langcode => $project_info) { if (empty($project_info->type)) { - $untranslated[$langcode] = $languages[$langcode]->name; + $untranslated[$langcode] = $languages[$langcode]->getName(); } elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) { - $available_updates[$langcode] = $languages[$langcode]->name; + $available_updates[$langcode] = $languages[$langcode]->getName(); } } } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index eda544d..2ffacc7 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -228,7 +228,7 @@ function locale_language_entity_insert(LanguageEntity $language) { // Changing the language settings impacts the interface: clear render cache. \Drupal::cache('render')->deleteAll(); // Force JavaScript translation file re-creation for the new language. - _locale_invalidate_js($language->id()); + _locale_invalidate_js($language->id); } /** @@ -239,7 +239,7 @@ function locale_language_entity_update(LanguageEntity $language) { // Changing the language settings impacts the interface: clear render cache. \Drupal::cache('render')->deleteAll(); // Force JavaScript translation file re-creation for the modified language. - _locale_invalidate_js($language->id()); + _locale_invalidate_js($language->id); } /** @@ -247,22 +247,22 @@ function locale_language_entity_update(LanguageEntity $language) { */ function locale_language_entity_delete(LanguageEntity $language) { // Remove translations. - \Drupal::service('locale.storage')->deleteTranslations(array('language' => $language->id())); + \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->id())); + locale_translate_delete_translation_files(array(), array($language->id)); // Remove translated configuration objects. - \Drupal\locale\Locale::config()->deleteLanguageTranslations($language->id()); + \Drupal\locale\Locale::config()->deleteLanguageTranslations($language->id); // Changing the language settings impacts the interface: - _locale_invalidate_js($language->id()); + _locale_invalidate_js($language->id); \Drupal::cache('render')->deleteAll(); // Clear locale translation caches. - locale_translation_status_delete_languages(array($language->id())); - \Drupal::cache()->delete('locale:' . $language->id()); + locale_translation_status_delete_languages(array($language->id)); + \Drupal::cache()->delete('locale:' . $language->id); } /** @@ -304,7 +304,7 @@ function locale_get_plural($count, $langcode = NULL) { // individually for each language. $plural_indexes = &drupal_static(__FUNCTION__ . ':plurals', array()); - $langcode = $langcode ? $langcode : $language_interface->id; + $langcode = $langcode ? $langcode : $language_interface->getId(); if (!isset($plural_indexes[$langcode][$count])) { // Retrieve and statically cache the plural formulas for all languages. @@ -591,11 +591,11 @@ function locale_js_translate(array $files = array()) { } // If necessary, rebuild the translation file for the current language. - if (!empty($parsed['refresh:' . $language_interface->id])) { + if (!empty($parsed['refresh:' . $language_interface->getId()])) { // 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->id]); + unset($parsed['refresh:' . $language_interface->getId()]); } // Store any changes after refresh was attempted. \Drupal::state()->set('system.javascript_parsed', $parsed); @@ -609,9 +609,9 @@ function locale_js_translate(array $files = array()) { // Add the translation JavaScript file to the page. $locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: array(); $translation_file = NULL; - if (!empty($files) && !empty($locale_javascripts[$language_interface->id])) { + if (!empty($files) && !empty($locale_javascripts[$language_interface->getId()])) { // Add the translation JavaScript file to the page. - $translation_file = $dir . '/' . $language_interface->id . '_' . $locale_javascripts[$language_interface->id] . '.js'; + $translation_file = $dir . '/' . $language_interface->getId() . '_' . $locale_javascripts[$language_interface->getId()] . '.js'; } return $translation_file; } @@ -629,7 +629,7 @@ function locale_library_alter(array &$library, $name) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); $settings['jquery']['ui']['datepicker'] = array( - 'isRTL' => $language_interface->direction == LanguageInterface::DIRECTION_RTL, + 'isRTL' => $language_interface->getDirection() == LanguageInterface::DIRECTION_RTL, 'firstDay' => \Drupal::config('system.date')->get('first_day'), ); $library['js'][] = array( @@ -666,7 +666,7 @@ function locale_form_language_admin_overview_form_alter(&$form, &$form_state) { 'translated' => 0, 'ratio' => 0, ); - if (!$language->locked && ($langcode != 'en' || locale_translate_english())) { + if (!empty($language->locked) && ($langcode != 'en' || locale_translate_english())) { $form['languages'][$langcode]['locale_statistics'] = array( '#markup' => l( t('@translated/@total (@ratio%)', array( @@ -802,20 +802,22 @@ function locale_system_file_system_settings_submit(&$form, $form_state) { * Implements hook_preprocess_HOOK() for node templates. */ function locale_preprocess_node(&$variables) { - if ($variables['node']->language()->id != LanguageInterface::LANGCODE_NOT_SPECIFIED) { - $language_interface = \Drupal::languageManager()->getCurrentLanguage(); + /** @var \Drupal\node\NodeInterface $node */ + $node = $variables['node']; + if ($node->language()->getId() != LanguageInterface::LANGCODE_NOT_SPECIFIED) { + $interface_language = \Drupal::languageManager()->getCurrentLanguage(); - $node_language = $variables['node']->language(); - if ($node_language->id != $language_interface->id) { + $node_language = $node->language(); + if ($node_language->getId() != $interface_language->getId()) { // If the node language was different from the page language, we should // add markup to identify the language. Otherwise the page language is // inherited. - $variables['attributes']['lang'] = $node_language->id; - if ($node_language->direction != $language_interface->direction) { + $variables['attributes']['lang'] = $node_language->getId(); + if ($node_language->getDirection() != $interface_language->getDirection()) { // If text direction is different form the page's text direction, add // direction information as well. $dir = array('ltr', 'rtl'); - $variables['attributes']['dir'] = $dir[$node_language->direction]; + $variables['attributes']['dir'] = $dir[$node_language->getDirection()]; } } } @@ -1267,7 +1269,7 @@ function _locale_rebuild_js($langcode = NULL) { // Only add strings with a translation to the translations array. $conditions = array( 'type' => 'javascript', - 'language' => $language->id, + 'language' => $language->getId(), 'translated' => TRUE, ); $translations = array(); @@ -1284,8 +1286,8 @@ function _locale_rebuild_js($langcode = NULL) { ); $locale_plurals = \Drupal::state()->get('locale.translation.plurals') ?: array(); - if (!empty($locale_plurals[$language->id]['formula'])) { - $data['pluralFormula'] = $locale_plurals[$language->id]['formula']; + if (!empty($locale_plurals[$language->getId()]['formula'])) { + $data['pluralFormula'] = $locale_plurals[$language->getId()]['formula']; } $data = 'Drupal.locale = ' . Json::encode($data) . ';'; @@ -1298,23 +1300,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->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] = ''; + $changed_hash = !isset($locale_javascripts[$language->getId()]) || ($locale_javascripts[$language->getId()] != $data_hash); + if (!empty($locale_javascripts[$language->getId()]) && (!$data || $changed_hash)) { + file_unmanaged_delete($dir . '/' . $language->getId() . '_' . $locale_javascripts[$language->getId()] . '.js'); + $locale_javascripts[$language->getId()] = ''; $status = 'deleted'; } // Only create a new file if the content has changed or the original file got // lost. - $dest = $dir . '/' . $language->id . '_' . $data_hash . '.js'; + $dest = $dir . '/' . $language->getId() . '_' . $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->id] = $data_hash; + $locale_javascripts[$language->getId()] = $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') { @@ -1332,7 +1334,7 @@ function _locale_rebuild_js($langcode = NULL) { } } else { - $locale_javascripts[$language->id] = ''; + $locale_javascripts[$language->getId()] = ''; $status = 'error'; } } @@ -1347,21 +1349,21 @@ function _locale_rebuild_js($langcode = NULL) { // Log the operation and return success flag. switch ($status) { case 'updated': - watchdog('locale', 'Updated JavaScript translation file for the language %language.', array('%language' => $language->name)); + watchdog('locale', 'Updated JavaScript translation file for the language %language.', array('%language' => $language->getName())); return TRUE; case 'rebuilt': - watchdog('locale', 'JavaScript translation file %file.js was lost.', array('%file' => $locale_javascripts[$language->id]), WATCHDOG_WARNING); + watchdog('locale', 'JavaScript translation file %file.js was lost.', array('%file' => $locale_javascripts[$language->getId()]), WATCHDOG_WARNING); // Proceed to the 'created' case as the JavaScript translation file has // been created again. case 'created': - watchdog('locale', 'Created JavaScript translation file for the language %language.', array('%language' => $language->name)); + watchdog('locale', 'Created JavaScript translation file for the language %language.', array('%language' => $language->getName())); return TRUE; case 'deleted': - watchdog('locale', 'Removed JavaScript translation file for the language %language because no translations currently exist for that language.', array('%language' => $language->name)); + watchdog('locale', 'Removed JavaScript translation file for the language %language because no translations currently exist for that language.', array('%language' => $language->getName())); return TRUE; case 'error': - watchdog('locale', 'An error occurred during creation of the JavaScript translation file for the language %language.', array('%language' => $language->name), WATCHDOG_ERROR); + watchdog('locale', 'An error occurred during creation of the JavaScript translation file for the language %language.', array('%language' => $language->getName()), WATCHDOG_ERROR); return FALSE; default: // No operation needed. diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index 8a07c4c..f7f6111 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -91,7 +91,7 @@ function locale_translation_status_form($form, &$form_state) { // Build data options for the select table. foreach($updates as $langcode => $update) { - $title = String::checkPlain($languages[$langcode]->name); + $title = String::checkPlain($languages[$langcode]->getName()); $locale_translation_update_info = array('#theme' => 'locale_translation_update_info'); foreach (array('updates', 'not_found') as $update_status) { if (isset($update[$update_status])) { diff --git a/core/modules/locale/src/Form/ExportForm.php b/core/modules/locale/src/Form/ExportForm.php index 70f611c..89adf49 100644 --- a/core/modules/locale/src/Form/ExportForm.php +++ b/core/modules/locale/src/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' => LanguageInterface::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. diff --git a/core/modules/locale/src/Form/ImportForm.php b/core/modules/locale/src/Form/ImportForm.php index 21b3150..e22cb52 100644 --- a/core/modules/locale/src/Form/ImportForm.php +++ b/core/modules/locale/src/Form/ImportForm.php @@ -81,7 +81,7 @@ public function buildForm(array $form, array &$form_state) { $existing_languages = array(); foreach ($languages as $langcode => $language) { if ($langcode != 'en' || locale_translate_english()) { - $existing_languages[$langcode] = $language->name; + $existing_languages[$langcode] = $language->getName(); } } @@ -179,7 +179,7 @@ public function submitForm(array &$form, array &$form_state) { 'id' => $form_state['values']['langcode'] )); $language = language_save($language); - drupal_set_message($this->t('The language %language has been created.', array('%language' => $this->t($language->name)))); + drupal_set_message($this->t('The language %language has been created.', array('%language' => $this->t($language->getName())))); } $options = array( 'langcode' => $form_state['values']['langcode'], diff --git a/core/modules/locale/src/Form/TranslateEditForm.php b/core/modules/locale/src/Form/TranslateEditForm.php index c846026..24066a4 100644 --- a/core/modules/locale/src/Form/TranslateEditForm.php +++ b/core/modules/locale/src/Form/TranslateEditForm.php @@ -33,7 +33,7 @@ public function buildForm(array $form, array &$form_state) { $this->languageManager->reset(); $languages = language_list(); - $langname = isset($langcode) ? $languages[$langcode]->name : "- None -"; + $langname = isset($langcode) ? $languages[$langcode]->getName() : "- None -"; $form['#attached']['library'][] = 'locale/drupal.locale.admin'; diff --git a/core/modules/locale/src/Form/TranslateFormBase.php b/core/modules/locale/src/Form/TranslateFormBase.php index e0e4ac2..9d1a4d1 100644 --- a/core/modules/locale/src/Form/TranslateFormBase.php +++ b/core/modules/locale/src/Form/TranslateFormBase.php @@ -165,12 +165,12 @@ protected function translateFilters() { $language_options = array(); foreach ($languages as $langcode => $language) { if ($langcode != 'en' || locale_translate_english()) { - $language_options[$langcode] = $language->name; + $language_options[$langcode] = $language->getName(); } } // Pick the current interface language code for the filter. - $default_langcode = $this->languageManager->getCurrentLanguage()->id; + $default_langcode = $this->languageManager->getCurrentLanguage()->getId(); if (!isset($language_options[$default_langcode])) { $available_langcodes = array_keys($language_options); $default_langcode = array_shift($available_langcodes); diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index 9e0f3de..1959007 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -314,7 +314,7 @@ public function translateString($name, $langcode, $source, $context) { * A boolean indicating if a language has configuration translations. */ public function hasTranslation($name, LanguageInterface $language) { - $translation = $this->languageManager->getLanguageConfigOverride($language->id, $name); + $translation = $this->languageManager->getLanguageConfigOverride($language->getId(), $name); return !$translation->isNew(); } diff --git a/core/modules/locale/src/Tests/LocalePathTest.php b/core/modules/locale/src/Tests/LocalePathTest.php index b8cc838..ee082a5 100644 --- a/core/modules/locale/src/Tests/LocalePathTest.php +++ b/core/modules/locale/src/Tests/LocalePathTest.php @@ -124,7 +124,7 @@ function testPathLanguageConfiguration() { $edit = array( 'source' => 'node/' . $first_node->id(), 'alias' => $custom_path, - 'langcode' => $first_node->language()->id, + 'langcode' => $first_node->language()->getId(), ); $this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']); @@ -133,7 +133,7 @@ function testPathLanguageConfiguration() { $edit = array( 'source' => 'node/' . $second_node->id(), 'alias' => $custom_path, - 'langcode' => $second_node->language()->id, + 'langcode' => $second_node->language()->getId(), ); $this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']); diff --git a/core/modules/locale/src/Tests/LocaleStringTest.php b/core/modules/locale/src/Tests/LocaleStringTest.php index a9b45ec..151a40f 100644 --- a/core/modules/locale/src/Tests/LocaleStringTest.php +++ b/core/modules/locale/src/Tests/LocaleStringTest.php @@ -193,8 +193,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; } diff --git a/core/modules/menu_link/src/MenuTree.php b/core/modules/menu_link/src/MenuTree.php index adbf85d..e54abb8 100644 --- a/core/modules/menu_link/src/MenuTree.php +++ b/core/modules/menu_link/src/MenuTree.php @@ -155,7 +155,7 @@ public function buildAllData($menu_name, $link = NULL, $max_depth = NULL) { $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->id . ':' . (int) $max_depth; + $cid = 'links:' . $menu_name . ':all:' . $mlid . ':' . $language_interface->getId() . ':' . (int) $max_depth; if (!isset($this->menuFullTrees[$cid])) { // If the static variable doesn't have the data, check {cache_menu}. @@ -218,7 +218,7 @@ public function buildPageData($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:' . $system_path . ':' . $language_interface->id . ':' . $page_not_403 . ':' . (int) $max_depth; + $cid = 'links:' . $menu_name . ':page:' . $system_path . ':' . $language_interface->getId() . ':' . $page_not_403 . ':' . (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 @@ -454,7 +454,7 @@ protected function doBuildTree($menu_name, array $parameters = array()) { if (isset($parameters['expanded'])) { sort($parameters['expanded']); } - $tree_cid = 'links:' . $menu_name . ':tree-data:' . $language_interface->id . ':' . hash('sha256', serialize($parameters)); + $tree_cid = 'links:' . $menu_name . ':tree-data:' . $language_interface->getId() . ':' . hash('sha256', serialize($parameters)); // If we do not have this tree in the static cache, check {cache_menu}. if (!isset($this->menuTree[$tree_cid])) { diff --git a/core/modules/menu_ui/src/Tests/MenuLanguageTest.php b/core/modules/menu_ui/src/Tests/MenuLanguageTest.php index 971e821..7bfaedc 100644 --- a/core/modules/menu_ui/src/Tests/MenuLanguageTest.php +++ b/core/modules/menu_ui/src/Tests/MenuLanguageTest.php @@ -181,7 +181,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'); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorFeedTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorFeedTest.php index 6b57800..3b4cfc2 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorFeedTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorFeedTest.php @@ -52,7 +52,7 @@ public function testAggregatorFeedImport() { $feed = entity_load('aggregator_feed', 5); $this->assertNotNull($feed->uuid()); $this->assertEqual($feed->title->value, 'Know Your Meme'); - $this->assertEqual($feed->language()->id, LanguageInterface::LANGCODE_NOT_SPECIFIED); + $this->assertEqual($feed->language()->getId(), LanguageInterface::LANGCODE_NOT_SPECIFIED); $this->assertEqual($feed->url->value, 'http://knowyourmeme.com/newsfeed.rss'); $this->assertEqual($feed->refresh->value, 900); $this->assertEqual($feed->checked->value, 1387659487); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorItemTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorItemTest.php index 520dccf..c08890b 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorItemTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorItemTest.php @@ -76,7 +76,7 @@ public function testAggregatorItem() { $this->assertEqual($item->getDescription(), "

What's new with Drupal 8?

"); $this->assertEqual($item->getLink(), 'https://groups.drupal.org/node/395218'); $this->assertEqual($item->getPostedTime(), 1389297196); - $this->assertEqual($item->language()->id, LanguageInterface::LANGCODE_NOT_SPECIFIED); + $this->assertEqual($item->language()->getId(), LanguageInterface::LANGCODE_NOT_SPECIFIED); $this->assertEqual($item->getGuid(), '395218 at https://groups.drupal.org'); } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockContentTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockContentTest.php index b6c2321..8fad857 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockContentTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockContentTest.php @@ -61,7 +61,7 @@ public function testBlockMigration() { $this->assertEqual('My block 1', $block->label()); $this->assertEqual(1, $block->getRevisionId()); $this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time()); - $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $block->language()->id); + $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $block->language()->getId()); $this->assertEqual('

My first custom block body

', $block->body->value); $this->assertEqual('full_html', $block->body->format); @@ -69,7 +69,7 @@ public function testBlockMigration() { $this->assertEqual('My block 2', $block->label()); $this->assertEqual(2, $block->getRevisionId()); $this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time()); - $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $block->language()->id); + $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $block->language()->getId()); $this->assertEqual('

My second custom block body

', $block->body->value); $this->assertEqual('full_html', $block->body->format); } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php index d07b02b..7dc1035 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php @@ -82,7 +82,7 @@ public function testComments() { $this->assertEqual(0, $comment->pid->target_id); $this->assertEqual(1, $comment->entity_id->target_id); $this->assertEqual('node', $comment->entity_type->value); - $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $comment->language()->id); + $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $comment->language()->getId()); $comment = entity_load('comment', 2); $this->assertEqual('The response to the second comment.', $comment->subject->value); diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index b0a806d..2da5e05 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -5,7 +5,6 @@ * Content administration and module settings user interface. */ -use Drupal\Core\Language\Language; use Drupal\node\NodeInterface; /** diff --git a/core/modules/node/node.install b/core/modules/node/node.install index d0d6d1c..e68f9c0 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -6,7 +6,6 @@ */ use Drupal\Component\Uuid\Uuid; -use Drupal\Core\Language\Language; /** * Implements hook_requirements(). diff --git a/core/modules/node/node.module b/core/modules/node/node.module index d4f7db0..c362e66 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1078,7 +1078,7 @@ function node_feed($nids = FALSE, $channel = array()) { 'title' => \Drupal::config('system.site')->get('name'), 'link' => $base_url, 'description' => $rss_config->get('channel.description'), - 'language' => $language_content->id + 'language' => $language_content->getId() ); $channel_extras = array_diff_key($channel, $channel_defaults); $channel = array_merge($channel_defaults, $channel); diff --git a/core/modules/node/node.tokens.inc b/core/modules/node/node.tokens.inc index 4e0f300..d165548 100644 --- a/core/modules/node/node.tokens.inc +++ b/core/modules/node/node.tokens.inc @@ -161,7 +161,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr break; case 'langcode': - $replacements[$original] = $sanitize ? String::checkPlain($node->language()->id) : $node->language()->id; + $replacements[$original] = $sanitize ? String::checkPlain($node->language()->getId()) : $node->language()->getId(); break; case 'url': diff --git a/core/modules/node/src/Access/NodeRevisionAccessCheck.php b/core/modules/node/src/Access/NodeRevisionAccessCheck.php index 66dc7e2..06da782 100644 --- a/core/modules/node/src/Access/NodeRevisionAccessCheck.php +++ b/core/modules/node/src/Access/NodeRevisionAccessCheck.php @@ -127,7 +127,7 @@ public function checkAccess(NodeInterface $node, AccountInterface $account, $op // If no language code was provided, default to the node revision's langcode. if (empty($langcode)) { - $langcode = $node->language()->id; + $langcode = $node->language()->getId(); } // Statically cache access by revision ID, language code, user account ID, diff --git a/core/modules/node/src/Controller/NodeController.php b/core/modules/node/src/Controller/NodeController.php index 812a3f8..f9a8335 100644 --- a/core/modules/node/src/Controller/NodeController.php +++ b/core/modules/node/src/Controller/NodeController.php @@ -109,7 +109,7 @@ public function add(NodeTypeInterface $node_type) { 'uid' => $account->id(), 'name' => $account->getUsername() ?: '', 'type' => $node_type->type, - 'langcode' => $langcode ? $langcode : $this->languageManager()->getCurrentLanguage()->id, + 'langcode' => $langcode ? $langcode : $this->languageManager()->getCurrentLanguage()->getId(), )); $form = $this->entityFormBuilder()->getForm($node); diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index 0cdac07..4a0784a 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -160,14 +160,14 @@ public function access($operation = 'view', AccountInterface $account = NULL) { * {@inheritdoc} */ public function prepareLangcode() { - $langcode = $this->language()->id; + $langcode = $this->language()->getId(); // If the Language module is enabled, try to use the language from content // negotiation. if (\Drupal::moduleHandler()->moduleExists('language')) { // Load languages the node exists in. $node_translations = $this->getTranslationLanguages(); // Load the language from content negotiation. - $content_negotiation_langcode = \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id; + $content_negotiation_langcode = \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); // If there is a translation available, use it. if (isset($node_translations[$content_negotiation_langcode])) { $langcode = $content_negotiation_langcode; diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 03ed3da..bcd72c4 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -80,7 +80,7 @@ public function form(array $form, array &$form_state) { $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', - '#default_value' => $node->getUntranslated()->language()->id, + '#default_value' => $node->getUntranslated()->language()->getId(), '#languages' => LanguageInterface::STATE_ALL, '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], ); diff --git a/core/modules/node/src/NodeGrantDatabaseStorage.php b/core/modules/node/src/NodeGrantDatabaseStorage.php index 9503713..8d34418 100644 --- a/core/modules/node/src/NodeGrantDatabaseStorage.php +++ b/core/modules/node/src/NodeGrantDatabaseStorage.php @@ -190,7 +190,7 @@ public function write(NodeInterface $node, array $grants, $realm = NULL, $delete $grant['nid'] = $node->id(); $grant['langcode'] = $grant_langcode; // The record with the original langcode is used as the fallback. - if ($grant['langcode'] == $node->language()->id) { + if ($grant['langcode'] == $node->language()->getId()) { $grant['fallback'] = 1; } else { diff --git a/core/modules/node/src/NodeListBuilder.php b/core/modules/node/src/NodeListBuilder.php index 4ddc56e..1c3fafd 100644 --- a/core/modules/node/src/NodeListBuilder.php +++ b/core/modules/node/src/NodeListBuilder.php @@ -96,7 +96,7 @@ public function buildRow(EntityInterface $entity) { '#theme' => 'mark', '#mark_type' => node_mark($entity->id(), $entity->getChangedTime()), ); - $langcode = $entity->language()->id; + $langcode = $entity->language()->getId(); $uri = $entity->urlInfo(); $options = $uri->getOptions(); $options += ($langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array()); diff --git a/core/modules/node/src/NodeViewBuilder.php b/core/modules/node/src/NodeViewBuilder.php index 606ef36..69aa43f 100644 --- a/core/modules/node/src/NodeViewBuilder.php +++ b/core/modules/node/src/NodeViewBuilder.php @@ -57,7 +57,7 @@ public function buildComponents(array &$build, array $entities, array $displays, $build[$id]['langcode'] = array( '#type' => 'item', '#title' => t('Language'), - '#markup' => $entity->language()->name, + '#markup' => $entity->language()->getName(), '#prefix' => '
', '#suffix' => '
' ); diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index 78cdedf..f144113 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -288,7 +288,7 @@ public function execute() { 'extra' => $extra, 'score' => $item->calculated_score, 'snippet' => search_excerpt($keys, $node->rendered, $item->langcode), - 'langcode' => $node->language()->id, + 'langcode' => $node->language()->getId(), ); } return $results; @@ -352,23 +352,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 = '

' . String::checkPlain($node->label($language->id)) . '

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

' . String::checkPlain($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()); } } @@ -456,7 +456,7 @@ public function searchFormAlter(array &$form, array &$form_state) { $language_list = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL); foreach ($language_list as $langcode => $language) { // Make locked languages appear special in the list. - $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(); } if (count($language_options) > 1) { $form['advanced']['lang-fieldset'] = array( diff --git a/core/modules/node/src/Plugin/views/field/Language.php b/core/modules/node/src/Plugin/views/field/Language.php index af705cb..9d12a1d 100644 --- a/core/modules/node/src/Plugin/views/field/Language.php +++ b/core/modules/node/src/Plugin/views/field/Language.php @@ -44,7 +44,7 @@ public function render(ResultRow $values) { // ready, see http://drupal.org/node/1616594. $value = $this->getValue($values); $language = language_load($value); - $value = $language ? $language->name : ''; + $value = $language ? $language->getName() : ''; return $this->renderLink($value, $values); } diff --git a/core/modules/node/src/Tests/NodeAccessLanguageTest.php b/core/modules/node/src/Tests/NodeAccessLanguageTest.php index 619fcac..e90b48b 100644 --- a/core/modules/node/src/Tests/NodeAccessLanguageTest.php +++ b/core/modules/node/src/Tests/NodeAccessLanguageTest.php @@ -66,7 +66,7 @@ function testNodeAccess() { // Creating a public node with langcode Hungarian, will be saved as the // fallback in node access table. $node_public_hu = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'private' => FALSE)); - $this->assertTrue($node_public_hu->language()->id == 'hu', 'Node created as Hungarian.'); + $this->assertTrue($node_public_hu->language()->getId() == 'hu', 'Node created as Hungarian.'); // Tests the default access is provided for the public Hungarian node. $this->assertNodeAccess($expected_node_access, $node_public_hu, $web_user); @@ -83,7 +83,7 @@ function testNodeAccess() { // Creating a public node with no special langcode, like when no language // module enabled. $node_public_no_language = $this->drupalCreateNode(array('private' => FALSE)); - $this->assertTrue($node_public_no_language->language()->id == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); + $this->assertTrue($node_public_no_language->language()->getId() == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); // Tests that access is granted if requested with no language. $this->assertNodeAccess($expected_node_access, $node_public_no_language, $web_user); @@ -101,7 +101,7 @@ function testNodeAccess() { \Drupal::entityManager()->getAccessController('node')->resetCache(); \Drupal::state()->set('node_access_test_secret_catalan', 1); $node_public_ca = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'ca', 'private' => FALSE)); - $this->assertTrue($node_public_ca->language()->id == 'ca', 'Node created as Catalan.'); + $this->assertTrue($node_public_ca->language()->getId() == 'ca', 'Node created as Catalan.'); // Tests that access is granted if requested with no language. $this->assertNodeAccess($expected_node_access, $node_public_no_language, $web_user); @@ -156,7 +156,7 @@ function testNodeAccessPrivate() { // Creating a private node with langcode Hungarian, will be saved as the // fallback in node access table. $node_private_hu = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'private' => TRUE)); - $this->assertTrue($node_private_hu->language()->id == 'hu', 'Node created as Hungarian.'); + $this->assertTrue($node_private_hu->language()->getId() == 'hu', 'Node created as Hungarian.'); // Tests the default access is not provided for the private Hungarian node. $this->assertNodeAccess($expected_node_access_no_access, $node_private_hu, $web_user); @@ -173,7 +173,7 @@ function testNodeAccessPrivate() { // Creating a private node with no special langcode, like when no language // module enabled. $node_private_no_language = $this->drupalCreateNode(array('private' => TRUE)); - $this->assertTrue($node_private_no_language->language()->id == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); + $this->assertTrue($node_private_no_language->language()->getId() == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); // Tests that access is not granted if requested with no language. $this->assertNodeAccess($expected_node_access_no_access, $node_private_no_language, $web_user); @@ -204,7 +204,7 @@ function testNodeAccessPrivate() { // node_access_test_secret_catalan flag works. $private_ca_user = $this->drupalCreateUser(array('access content', 'node test view')); $node_private_ca = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'ca', 'private' => TRUE)); - $this->assertTrue($node_private_ca->language()->id == 'ca', 'Node created as Catalan.'); + $this->assertTrue($node_private_ca->language()->getId() == 'ca', 'Node created as Catalan.'); // Tests that Catalan is still not accessible to either user. $this->assertNodeAccess($expected_node_access_no_access, $node_private_ca, $web_user, 'ca'); @@ -236,17 +236,17 @@ function testNodeAccessQueryTag() { // Creating a private node with langcode Hungarian, will be saved as // the fallback in node access table. $node_private = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'private' => TRUE)); - $this->assertTrue($node_private->language()->id == 'hu', 'Node created as Hungarian.'); + $this->assertTrue($node_private->language()->getId() == 'hu', 'Node created as Hungarian.'); // Creating a public node with langcode Hungarian, will be saved as // the fallback in node access table. $node_public = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'private' => FALSE)); - $this->assertTrue($node_public->language()->id == 'hu', 'Node created as Hungarian.'); + $this->assertTrue($node_public->language()->getId() == 'hu', 'Node created as Hungarian.'); // Creating a public node with no special langcode, like when no language // module enabled. $node_no_language = $this->drupalCreateNode(array('private' => FALSE)); - $this->assertTrue($node_no_language->language()->id == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); + $this->assertTrue($node_no_language->language()->getId() == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); // Query the nodes table as the web user with the node access tag and no // specific langcode. diff --git a/core/modules/node/src/Tests/NodeFieldMultilingualTestCase.php b/core/modules/node/src/Tests/NodeFieldMultilingualTestCase.php index 319fdb4..e536e71 100644 --- a/core/modules/node/src/Tests/NodeFieldMultilingualTestCase.php +++ b/core/modules/node/src/Tests/NodeFieldMultilingualTestCase.php @@ -87,7 +87,7 @@ function testMultilingualNodeForm() { // Check that the node exists in the database. $node = $this->drupalGetNodeByTitle($edit[$title_key]); $this->assertTrue($node, 'Node found in database.'); - $this->assertTrue($node->language()->id == $langcode && $node->body->value == $body_value, 'Field language correctly set.'); + $this->assertTrue($node->language()->getId() == $langcode && $node->body->value == $body_value, 'Field language correctly set.'); // Change node language. $langcode = 'it'; @@ -99,7 +99,7 @@ function testMultilingualNodeForm() { $this->drupalPostForm(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle($edit[$title_key], TRUE); $this->assertTrue($node, 'Node found in database.'); - $this->assertTrue($node->language()->id == $langcode && $node->body->value == $body_value, 'Field language correctly changed.'); + $this->assertTrue($node->language()->getId() == $langcode && $node->body->value == $body_value, 'Field language correctly changed.'); // Enable content language URL detection. $this->container->get('language_negotiator')->saveConfiguration(LanguageInterface::TYPE_CONTENT, array(LanguageNegotiationUrl::METHOD_ID => 0)); diff --git a/core/modules/node/src/Tests/NodeLastChangedTest.php b/core/modules/node/src/Tests/NodeLastChangedTest.php index aa1dbfa..a06a23b 100644 --- a/core/modules/node/src/Tests/NodeLastChangedTest.php +++ b/core/modules/node/src/Tests/NodeLastChangedTest.php @@ -46,7 +46,7 @@ function testNodeLastChanged() { $changed_timestamp = node_last_changed($node->id()); $this->assertEqual($changed_timestamp, $node->getChangedTime(), 'Expected last changed timestamp returned.'); - $changed_timestamp = node_last_changed($node->id(), $node->language()->id); + $changed_timestamp = node_last_changed($node->id(), $node->language()->getId()); $this->assertEqual($changed_timestamp, $node->getChangedTime(), 'Expected last changed timestamp returned.'); } } diff --git a/core/modules/node/src/Tests/NodeTokenReplaceTest.php b/core/modules/node/src/Tests/NodeTokenReplaceTest.php index e9c1a1f..96cebe0 100644 --- a/core/modules/node/src/Tests/NodeTokenReplaceTest.php +++ b/core/modules/node/src/Tests/NodeTokenReplaceTest.php @@ -76,20 +76,20 @@ function testNodeTokenReplacement() { $tests['[node:title]'] = String::checkPlain($node->getTitle()); $tests['[node:body]'] = $node->body->processed; $tests['[node:summary]'] = $node->body->summary_processed; - $tests['[node:langcode]'] = String::checkPlain($node->language()->id); + $tests['[node:langcode]'] = String::checkPlain($node->language()->getId()); $tests['[node:url]'] = url('node/' . $node->id(), $url_options); $tests['[node:edit-url]'] = url('node/' . $node->id() . '/edit', $url_options); $tests['[node:author]'] = String::checkPlain($account->getUsername()); $tests['[node:author:uid]'] = $node->getOwnerId(); $tests['[node:author:name]'] = String::checkPlain($account->getUsername()); - $tests['[node:created:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->getCreatedTime(), 2, $this->interfaceLanguage->id); - $tests['[node:changed:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->getChangedTime(), 2, $this->interfaceLanguage->id); + $tests['[node:created:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->getCreatedTime(), 2, $this->interfaceLanguage->getId()); + $tests['[node:changed:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->getChangedTime(), 2, $this->interfaceLanguage->getId()); // 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 = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->interfaceLanguage->id)); + $output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->interfaceLanguage->getId())); $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced.', array('%token' => $input))); } @@ -97,11 +97,11 @@ function testNodeTokenReplacement() { $tests['[node:title]'] = $node->getTitle(); $tests['[node:body]'] = $node->body->value; $tests['[node:summary]'] = $node->body->summary; - $tests['[node:langcode]'] = $node->language()->id; + $tests['[node:langcode]'] = $node->language()->getId(); $tests['[node:author:name]'] = $account->getUsername(); foreach ($tests as $input => $expected) { - $output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->interfaceLanguage->id, 'sanitize' => FALSE)); + $output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->interfaceLanguage->getId(), 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced.', array('%token' => $input))); } diff --git a/core/modules/path/src/Form/PathFormBase.php b/core/modules/path/src/Form/PathFormBase.php index a9e80c4..75f7cc4 100644 --- a/core/modules/path/src/Form/PathFormBase.php +++ b/core/modules/path/src/Form/PathFormBase.php @@ -102,7 +102,7 @@ public function buildForm(array $form, array &$form_state, $pid = NULL) { $languages = \Drupal::languageManager()->getLanguages(); $language_options = array(); foreach ($languages as $langcode => $language) { - $language_options[$langcode] = $language->name; + $language_options[$langcode] = $language->getName(); } $form['langcode'] = array( diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index 6590b90..4c84c84 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -37,7 +37,7 @@ function template_preprocess_search_result(&$variables) { $result = $variables['result']; $variables['url'] = check_url($result['link']); $variables['title'] = String::checkPlain($result['title']); - if (isset($result['language']) && $result['language'] != $language_interface->id && $result['language'] != LanguageInterface::LANGCODE_NOT_SPECIFIED) { + if (isset($result['language']) && $result['language'] != $language_interface->getId() && $result['language'] != LanguageInterface::LANGCODE_NOT_SPECIFIED) { $variables['title_attributes']['lang'] = $result['language']; $variables['content_attributes']['lang'] = $result['language']; } diff --git a/core/modules/shortcut/shortcut.install b/core/modules/shortcut/shortcut.install index be6f8b2..7e79c06 100644 --- a/core/modules/shortcut/shortcut.install +++ b/core/modules/shortcut/shortcut.install @@ -6,7 +6,6 @@ */ use Drupal\Core\Database\Database; -use Drupal\Core\Language\Language; /** * Implements hook_schema(). diff --git a/core/modules/shortcut/src/ShortcutForm.php b/core/modules/shortcut/src/ShortcutForm.php index 33c169a..89606d1 100644 --- a/core/modules/shortcut/src/ShortcutForm.php +++ b/core/modules/shortcut/src/ShortcutForm.php @@ -40,7 +40,7 @@ public function form(array $form, array &$form_state) { $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', - '#default_value' => $this->entity->getUntranslated()->language()->id, + '#default_value' => $this->entity->getUntranslated()->language()->getId(), '#languages' => LanguageInterface::STATE_ALL, ); diff --git a/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php b/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php index e1f0f4b..fc418f6 100644 --- a/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php +++ b/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php @@ -54,7 +54,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->id)); + $output = \Drupal::token()->replace($input, array('node' => $node), array('langcode' => $language_interface->getId())); $this->assertEqual($output, $expected, format_string('Statistics token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/system/core.api.php b/core/modules/system/core.api.php index 02c1cea..13dd84e 100644 --- a/core/modules/system/core.api.php +++ b/core/modules/system/core.api.php @@ -414,7 +414,7 @@ * * Example: * @code - * $cid = 'mymodule_example:' . \Drupal::languageManager()->getCurrentLanguage()->id(); + * $cid = 'mymodule_example:' . \Drupal::languageManager()->getCurrentLanguage()->getId(); * * $data = NULL; * if ($cache = \Drupal::cache()->get($cid)) { diff --git a/core/modules/system/language.api.php b/core/modules/system/language.api.php index 1fb40e2..5a72e42 100644 --- a/core/modules/system/language.api.php +++ b/core/modules/system/language.api.php @@ -30,7 +30,7 @@ function hook_language_switch_links_alter(array &$links, $type, $path) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); if ($type == LanguageInterface::TYPE_CONTENT && isset($links[$language_interface->id])) { - foreach ($links[$language_interface->id] as $link) { + foreach ($links[$language_interface->getId()] as $link) { $link['attributes']['class'][] = 'active-language'; } } diff --git a/core/modules/system/src/Tests/Common/FormatDateTest.php b/core/modules/system/src/Tests/Common/FormatDateTest.php index 7fd5683..3ddbf14 100644 --- a/core/modules/system/src/Tests/Common/FormatDateTest.php +++ b/core/modules/system/src/Tests/Common/FormatDateTest.php @@ -133,8 +133,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->id(), TRUE); - $real_language = $language_interface->id; - $language_interface->id = $user->getPreferredLangcode(); + $real_language = $language_interface->getId(); + $language_interface->setId($user->getPreferredLangcode()); // Simulate a Drupal bootstrap with the logged-in user. date_default_timezone_set(drupal_get_user_timezone()); @@ -156,7 +156,7 @@ function testFormatDate() { // Restore the original user and language, and enable session saving. $user = $real_user; - $language_interface->id = $real_language; + $language_interface->setId($real_language); // Restore default time zone. date_default_timezone_set(drupal_get_user_timezone()); \Drupal::service('session_manager')->enable(); diff --git a/core/modules/system/src/Tests/Common/UrlTest.php b/core/modules/system/src/Tests/Common/UrlTest.php index 7cda6a3..d59492d 100644 --- a/core/modules/system/src/Tests/Common/UrlTest.php +++ b/core/modules/system/src/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. diff --git a/core/modules/system/src/Tests/Entity/EntityFieldTest.php b/core/modules/system/src/Tests/Entity/EntityFieldTest.php index 91cbacb..700bf84 100644 --- a/core/modules/system/src/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFieldTest.php @@ -189,14 +189,14 @@ protected function assertReadWrite($entity_type) { $this->assertEqual(\Drupal::languageManager()->getLanguage(LanguageInterface::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 = \Drupal::languageManager()->getDefaultLanguage()->id; - $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->id, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); + $entity->langcode->value = \Drupal::languageManager()->getDefaultLanguage()->getId(); + $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $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 = LanguageInterface::LANGCODE_NOT_SPECIFIED; $entity->langcode->language = \Drupal::languageManager()->getDefaultLanguage(); - $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->id, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); + $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $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/src/Tests/Entity/EntityLanguageTestBase.php b/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php index c76fc97..44c2279 100644 --- a/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php @@ -100,7 +100,7 @@ function setUp() { // Create the default languages. $default_language = language_save($this->languageManager->getDefaultLanguage()); - $languages = $this->languageManager->getDefaultLockedLanguages($default_language->weight); + $languages = $this->languageManager->getDefaultLockedLanguages($default_language->getWeight()); foreach ($languages as $language) { language_save($language); } @@ -113,7 +113,7 @@ function setUp() { 'name' => $this->randomString(), 'weight' => $i, )); - $this->langcodes[$i] = $language->id; + $this->langcodes[$i] = $language->getId(); language_save($language); } } diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php index 41806e3..1240ec1 100644 --- a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php @@ -46,7 +46,7 @@ function setUp() { 'id' => 'l' . $i, 'name' => $this->randomString(), )); - $this->langcodes[$i] = $language->id; + $this->langcodes[$i] = $language->getId(); language_save($language); } } @@ -70,12 +70,12 @@ function testEntityFormLanguage() { $this->drupalPostForm(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); - $this->assertTrue($node->language()->id == $form_langcode, 'Form language is the same as the entity language.'); + $this->assertTrue($node->language()->getId() == $form_langcode, 'Form language is the same as the entity language.'); // Edit the node and test the form language. $this->drupalGet($this->langcodes[0] . '/node/' . $node->id() . '/edit'); $form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: FALSE; - $this->assertTrue($node->language()->id == $form_langcode, 'Form language is the same as the entity language.'); + $this->assertTrue($node->language()->getId() == $form_langcode, 'Form language is the same as the entity language.'); // Explicitly set form langcode. $langcode = $this->langcodes[0]; diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php index 8c2a440..1e5a08a 100644 --- a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php @@ -44,7 +44,7 @@ protected function _testEntityLanguageMethods($entity_type) { 'name' => 'test', 'user_id' => $this->container->get('current_user')->id(), )); - $this->assertEqual($entity->language()->id, LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', array('%entity_type' => $entity_type))); + $this->assertEqual($entity->language()->getId(), LanguageInterface::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. @@ -152,7 +152,7 @@ protected function _testMultilingualProperties($entity_type) { $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid)); $entity->save(); $entity = entity_load($entity_type, $entity->id()); - $default_langcode = $entity->language()->id; + $default_langcode = $entity->language()->getId(); $this->assertEqual($default_langcode, LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity created as language neutral.', array('%entity_type' => $entity_type))); $field = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get('name'); $this->assertEqual($name, $field->value, format_string('%entity_type: The entity name has been correctly stored as language neutral.', array('%entity_type' => $entity_type))); @@ -172,7 +172,7 @@ protected function _testMultilingualProperties($entity_type) { $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid, 'langcode' => $langcode)); $entity->save(); $entity = entity_load($entity_type, $entity->id()); - $default_langcode = $entity->language()->id; + $default_langcode = $entity->language()->getId(); $this->assertEqual($default_langcode, $langcode, format_string('%entity_type: Entity created as language specific.', array('%entity_type' => $entity_type))); $field = $entity->getTranslation($langcode)->get('name'); $this->assertEqual($name, $field->value, format_string('%entity_type: The entity name has been correctly stored as a language-aware property.', array('%entity_type' => $entity_type))); @@ -221,7 +221,7 @@ protected function _testMultilingualProperties($entity_type) { ); $field = $entity->getTranslation($langcode)->get('name'); $this->assertEqual($properties[$langcode]['name'][0], $field->value, format_string('%entity_type: The entity name has been correctly stored for language %langcode.', $args)); - $field_langcode = ($langcode == $entity->language()->id) ? $default_langcode : $langcode; + $field_langcode = ($langcode == $entity->language()->getId()) ? $default_langcode : $langcode; $this->assertEqual($field_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expected langcode %langcode.', $args)); $this->assertEqual($properties[$langcode]['user_id'][0], $entity->getTranslation($langcode)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored for language %langcode.', $args)); } @@ -320,8 +320,8 @@ function testEntityTranslationAPI() { $translation = $entity->addTranslation($langcode); $this->assertNotIdentical($entity, $translation, 'The entity and the translation object differ from one another.'); $this->assertTrue($entity->hasTranslation($langcode), 'The new translation exists.'); - $this->assertEqual($translation->language()->id, $langcode, 'The translation language matches the specified one.'); - $this->assertEqual($translation->getUntranslated()->language()->id, $default_langcode, 'The original language can still be retrieved.'); + $this->assertEqual($translation->language()->getId(), $langcode, 'The translation language matches the specified one.'); + $this->assertEqual($translation->getUntranslated()->language()->getId(), $default_langcode, 'The original language can still be retrieved.'); $translation->name->value = $name_translated; $this->assertEqual($entity->name->value, $name, 'The original name is retained after setting a translated value.'); $entity->name->value = $name; @@ -335,16 +335,16 @@ function testEntityTranslationAPI() { // Check that after loading an entity the language is the default one. $entity = $this->reloadEntity($entity); - $this->assertEqual($entity->language()->id, $default_langcode, 'The loaded entity is the original one.'); + $this->assertEqual($entity->language()->getId(), $default_langcode, 'The loaded entity is the original one.'); // Add another translation and check that everything works as expected. A // new translation object can be obtained also by just specifying a valid // language. $langcode2 = $this->langcodes[2]; $translation = $entity->getTranslation($langcode2); - $value = $entity !== $translation && $translation->language()->id == $langcode2 && $entity->hasTranslation($langcode2); + $value = $entity !== $translation && $translation->language()->getId() == $langcode2 && $entity->hasTranslation($langcode2); $this->assertTrue($value, 'A new translation object can be obtained also by specifying a valid language.'); - $this->assertEqual($entity->language()->id, $default_langcode, 'The original language has been preserved.'); + $this->assertEqual($entity->language()->getId(), $default_langcode, 'The original language has been preserved.'); $translation->save(); $hooks = $this->getHooksInfo(); $this->assertEqual($hooks['entity_translation_insert'], $langcode2, 'The generic entity translation insertion hook has fired.'); @@ -448,7 +448,7 @@ function testEntityTranslationAPI() { * Tests language fallback applied to field and entity translations. */ function testLanguageFallback() { - $current_langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id; + $current_langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); $this->langcodes[] = $current_langcode; $values = array(); @@ -472,21 +472,21 @@ function testLanguageFallback() { // Check that retrieveing the current translation works as expected. $entity = $this->reloadEntity($entity); $translation = $this->entityManager->getTranslationFromContext($entity, $langcode2); - $this->assertEqual($translation->language()->id, $default_langcode, 'The current translation language matches the expected one.'); + $this->assertEqual($translation->language()->getId(), $default_langcode, 'The current translation language matches the expected one.'); // Check that language fallback respects language weight by default. $languages = $this->languageManager->getLanguages(); - $languages[$langcode]->weight = -1; + $languages[$langcode]->setWeight(-1); language_save($languages[$langcode]); $translation = $this->entityManager->getTranslationFromContext($entity, $langcode2); - $this->assertEqual($translation->language()->id, $langcode, 'The current translation language matches the expected one.'); + $this->assertEqual($translation->language()->getId(), $langcode, 'The current translation language matches the expected one.'); // Check that the current translation is properly returned. $translation = $this->entityManager->getTranslationFromContext($entity); - $this->assertEqual($langcode, $translation->language()->id, 'The current translation language matches the topmost language fallback candidate.'); + $this->assertEqual($langcode, $translation->language()->getId(), 'The current translation language matches the topmost language fallback candidate.'); $entity->addTranslation($current_langcode, $values[$current_langcode]); $translation = $this->entityManager->getTranslationFromContext($entity); - $this->assertEqual($current_langcode, $translation->language()->id, 'The current translation language matches the current language.'); + $this->assertEqual($current_langcode, $translation->language()->getId(), 'The current translation language matches the current language.'); // Check that if the entity has no translation no fallback is applied. $entity2 = $controller->create(array('langcode' => $default_langcode)); diff --git a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php index e82129e..b8bc2a2 100644 --- a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php +++ b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php @@ -117,13 +117,13 @@ function testFieldLoad() { for ($delta = 0; $delta <= $this->field_cardinality; $delta++) { $value = mt_rand(1, 127); $values[$revision_id][] = $value; - $query->values(array($bundle, 0, $entity->id(), $revision_id, $delta, $entity->language()->id, $value)); + $query->values(array($bundle, 0, $entity->id(), $revision_id, $delta, $entity->language()->getId(), $value)); } $query->execute(); } $query = db_insert($this->table)->fields($columns); foreach ($values[$revision_id] as $delta => $value) { - $query->values(array($bundle, 0, $entity->id(), $revision_id, $delta, $entity->language()->id, $value)); + $query->values(array($bundle, 0, $entity->id(), $revision_id, $delta, $entity->language()->getId(), $value)); } $query->execute(); @@ -187,7 +187,7 @@ function testFieldWrite() { 'deleted' => 0, 'entity_id' => $entity->id(), 'revision_id' => $entity->getRevisionId(), - 'langcode' => $entity->language()->id, + 'langcode' => $entity->language()->getId(), 'delta' => $delta, $this->field_name . '_value' => $values[$delta]['value'], ); @@ -210,7 +210,7 @@ function testFieldWrite() { 'deleted' => 0, 'entity_id' => $entity->id(), 'revision_id' => $entity->getRevisionId(), - 'langcode' => $entity->language()->id, + 'langcode' => $entity->language()->getId(), 'delta' => $delta, $this->field_name . '_value' => $values[$delta]['value'], ); @@ -238,7 +238,7 @@ function testFieldWrite() { 'deleted' => 0, 'entity_id' => $entity->id(), 'revision_id' => $revision_id, - 'langcode' => $entity->language()->id, + 'langcode' => $entity->language()->getId(), 'delta' => $delta, $this->field_name . '_value' => $values[$delta]['value'], ); diff --git a/core/modules/system/src/Tests/Entity/FieldTranslationSqlStorageTest.php b/core/modules/system/src/Tests/Entity/FieldTranslationSqlStorageTest.php index ef08f17..a162594 100644 --- a/core/modules/system/src/Tests/Entity/FieldTranslationSqlStorageTest.php +++ b/core/modules/system/src/Tests/Entity/FieldTranslationSqlStorageTest.php @@ -9,8 +9,8 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityDatabaseStorage; -use Drupal\Core\Language\LanguageInterface; use Drupal\field\Entity\FieldConfig; +use Drupal\Core\Language\LanguageInterface; /** * Tests entity translation. @@ -87,7 +87,7 @@ protected function assertFieldStorageLangcode(ContentEntityInterface $entity, $m $status = TRUE; $entity_type = $entity->getEntityTypeId(); $id = $entity->id(); - $langcode = $entity->getUntranslated()->language()->id; + $langcode = $entity->getUntranslated()->language()->getId(); $fields = array($this->field_name, $this->untranslatable_field_name); foreach ($fields as $field_name) { diff --git a/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php b/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php index f4171f0..4d68e49 100644 --- a/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php +++ b/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php @@ -8,9 +8,9 @@ namespace Drupal\system\Tests\Form; use Drupal\Component\Serialization\Json; -use Drupal\Core\Language\LanguageInterface; use Drupal\simpletest\WebTestBase; use Drupal\Core\Language\Language; +use Drupal\Core\Language\LanguageInterface; /** * Functional tests for the language select form element. @@ -63,7 +63,7 @@ function testLanguageSelectElementOptions() { $this->assertField($id, format_string('The @id field was found on the page.', array('@id' => $id))); $options = array(); foreach ($this->container->get('language_manager')->getLanguages($flags) as $langcode => $language) { - $options[$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; + $options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName(); } $this->_testLanguageSelectElementOptions($id, $options); } diff --git a/core/modules/system/src/Tests/KeyValueStore/KeyValueContentEntityStorageTest.php b/core/modules/system/src/Tests/KeyValueStore/KeyValueContentEntityStorageTest.php index 10aec9b..5930939 100644 --- a/core/modules/system/src/Tests/KeyValueStore/KeyValueContentEntityStorageTest.php +++ b/core/modules/system/src/Tests/KeyValueStore/KeyValueContentEntityStorageTest.php @@ -38,7 +38,7 @@ public static function getInfo() { * Tests CRUD operations. */ function testCRUD() { - $default_langcode = language_default()->id; + $default_langcode = language_default()->getId(); // Verify default properties on a newly created empty entity. $empty = entity_create('entity_test_label'); $this->assertIdentical($empty->id->value, NULL); diff --git a/core/modules/system/src/Tests/Mail/MailTest.php b/core/modules/system/src/Tests/Mail/MailTest.php index 95ac32f..d0805b7 100644 --- a/core/modules/system/src/Tests/Mail/MailTest.php +++ b/core/modules/system/src/Tests/Mail/MailTest.php @@ -66,7 +66,7 @@ public function testCancelMessage() { \Drupal::state()->set('system.test_mail_collector', array()); // Send a test message that simpletest_mail_alter should cancel. - drupal_mail('simpletest', 'cancel_test', 'cancel@example.com', $language_interface->id); + drupal_mail('simpletest', 'cancel_test', 'cancel@example.com', $language_interface->getId()); // Retrieve sent message. $captured_emails = \Drupal::state()->get('system.test_mail_collector'); $sent_message = end($captured_emails); diff --git a/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php b/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php index 4ea7da1..e11701f 100644 --- a/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php +++ b/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php @@ -45,7 +45,7 @@ public function testSystemTokenRecognition() { foreach ($tests as $test) { $input = $test['prefix'] . '[site:name]' . $test['suffix']; $expected = $test['prefix'] . 'Drupal' . $test['suffix']; - $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->id)); + $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->getId())); $this->assertTrue($output == $expected, format_string('Token recognized in string %string', array('%string' => $input))); } @@ -66,12 +66,12 @@ public function testClear() { // Replace with with the clear parameter, only the valid token should remain. $target = String::checkPlain(\Drupal::config('system.site')->get('name')); - $result = $this->tokenService->replace($source, array(), array('langcode' => $this->interfaceLanguage->id, 'clear' => TRUE)); + $result = $this->tokenService->replace($source, array(), array('langcode' => $this->interfaceLanguage->getId(), 'clear' => TRUE)); $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.'); $target .= '[user:name]'; $target .= '[bogus:token]'; - $result = $this->tokenService->replace($source, array(), array('langcode' => $this->interfaceLanguage->id)); + $result = $this->tokenService->replace($source, array(), array('langcode' => $this->interfaceLanguage->getId())); $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.'); } @@ -111,7 +111,7 @@ public function testSystemSiteTokenReplacement() { $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { - $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->id)); + $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->getId())); $this->assertEqual($output, $expected, format_string('Sanitized system site information token %token replaced.', array('%token' => $input))); } @@ -120,7 +120,7 @@ public function testSystemSiteTokenReplacement() { $tests['[site:slogan]'] = $config->get('slogan'); foreach ($tests as $input => $expected) { - $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->id, 'sanitize' => FALSE)); + $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->getId(), 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized system site information token %token replaced.', array('%token' => $input))); } @@ -146,18 +146,18 @@ public function testSystemDateTokenReplacement() { // Generate and test tokens. $tests = array(); $date_service = \Drupal::service('date'); - $tests['[date:short]'] = $date_service->format($date, 'short', '', NULL, $this->interfaceLanguage->id); - $tests['[date:medium]'] = $date_service->format($date, 'medium', '', NULL, $this->interfaceLanguage->id); - $tests['[date:long]'] = $date_service->format($date, 'long', '', NULL, $this->interfaceLanguage->id); - $tests['[date:custom:m/j/Y]'] = $date_service->format($date, 'custom', 'm/j/Y', NULL, $this->interfaceLanguage->id); - $tests['[date:since]'] = $date_service->formatInterval(REQUEST_TIME - $date, 2, $this->interfaceLanguage->id); + $tests['[date:short]'] = $date_service->format($date, 'short', '', NULL, $this->interfaceLanguage->getId()); + $tests['[date:medium]'] = $date_service->format($date, 'medium', '', NULL, $this->interfaceLanguage->getId()); + $tests['[date:long]'] = $date_service->format($date, 'long', '', NULL, $this->interfaceLanguage->getId()); + $tests['[date:custom:m/j/Y]'] = $date_service->format($date, 'custom', 'm/j/Y', NULL, $this->interfaceLanguage->getId()); + $tests['[date:since]'] = $date_service->formatInterval(REQUEST_TIME - $date, 2, $this->interfaceLanguage->getId()); $tests['[date:raw]'] = Xss::filter($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 = $this->tokenService->replace($input, array('date' => $date), array('langcode' => $this->interfaceLanguage->id)); + $output = $this->tokenService->replace($input, array('date' => $date), array('langcode' => $this->interfaceLanguage->getId())); $this->assertEqual($output, $expected, format_string('Date token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/system/src/Tests/Theme/TwigTransTest.php b/core/modules/system/src/Tests/Theme/TwigTransTest.php index 9b6fd00..8027b7a 100644 --- a/core/modules/system/src/Tests/Theme/TwigTransTest.php +++ b/core/modules/system/src/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'); } /** diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 11fd88f..7ad1da3 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -7,6 +7,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Utility\UpdateException; +use Drupal\Core\Language\LanguageInterface; /** * @addtogroup hooks @@ -313,7 +314,7 @@ function hook_library_alter(array &$library, $name) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); $settings['jquery']['ui']['datepicker'] = array( - 'isRTL' => $language_interface->direction == LanguageInterface::DIRECTION_RTL, + 'isRTL' => $language_interface->getDirection() == LanguageInterface::DIRECTION_RTL, 'firstDay' => \Drupal::config('system.date')->get('first_day'), ); $library['js'][] = array( diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 6161819..5a7b9ac 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -8,7 +8,6 @@ use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Environment; use Drupal\Core\Database\Database; -use Drupal\Core\Language\Language; use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\PublicStream; diff --git a/core/modules/system/system.module b/core/modules/system/system.module index ac44ab5..c736458 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -978,7 +978,7 @@ function system_page_build(&$page) { array( 'path' => current_path(), 'front' => drupal_is_front_page(), - 'language' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL)->id, + 'language' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(), 'query' => \Drupal::service('request')->query->all(), ) ); diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 6c3a078..dd3886a 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -392,28 +392,28 @@ function entity_test_entity_operation_alter(array &$operations, EntityInterface * Implements hook_entity_translation_insert(). */ function entity_test_entity_translation_insert(EntityInterface $translation) { - _entity_test_record_hooks('entity_translation_insert', $translation->language()->id); + _entity_test_record_hooks('entity_translation_insert', $translation->language()->getId()); } /** * Implements hook_entity_translation_delete(). */ function entity_test_entity_translation_delete(EntityInterface $translation) { - _entity_test_record_hooks('entity_translation_delete', $translation->language()->id); + _entity_test_record_hooks('entity_translation_delete', $translation->language()->getId()); } /** * Implements hook_ENTITY_TYPE_translation_insert(). */ function entity_test_entity_test_mul_translation_insert(EntityInterface $translation) { - _entity_test_record_hooks('entity_test_mul_translation_insert', $translation->language()->id); + _entity_test_record_hooks('entity_test_mul_translation_insert', $translation->language()->getId()); } /** * Implements hook_ENTITY_TYPE_translation_delete(). */ function entity_test_entity_test_mul_translation_delete(EntityInterface $translation) { - _entity_test_record_hooks('entity_test_mul_translation_delete', $translation->language()->id); + _entity_test_record_hooks('entity_test_mul_translation_delete', $translation->language()->getId()); } /** diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php index 2ca9d0d..5aa5bde 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php @@ -44,7 +44,7 @@ public function form(array $form, array &$form_state) { $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', - '#default_value' => $entity->getUntranslated()->language()->id, + '#default_value' => $entity->getUntranslated()->language()->getId(), '#languages' => LanguageInterface::STATE_ALL, ); diff --git a/core/modules/system/tests/modules/plugin_test/src/Plugin/CachedMockBlockManager.php b/core/modules/system/tests/modules/plugin_test/src/Plugin/CachedMockBlockManager.php index 4eb2aee..b1bb1d8 100644 --- a/core/modules/system/tests/modules/plugin_test/src/Plugin/CachedMockBlockManager.php +++ b/core/modules/system/tests/modules/plugin_test/src/Plugin/CachedMockBlockManager.php @@ -24,6 +24,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:' . \Drupal::languageManager()->getCurrentLanguage()->id, 'default', 1542646800, array('plugin_test')); + $this->discovery = new CacheDecorator($this->discovery, 'mock_block:' . \Drupal::languageManager()->getCurrentLanguage()->getId(), 'default', 1542646800, array('plugin_test')); } } diff --git a/core/modules/system/theme.api.php b/core/modules/system/theme.api.php index 08c9cf0..bf18b47 100644 --- a/core/modules/system/theme.api.php +++ b/core/modules/system/theme.api.php @@ -324,7 +324,7 @@ function hook_theme_suggestions_HOOK(array $variables) { */ function hook_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { // Add an interface-language specific suggestion to all theme hooks. - $suggestions[] = $hook . '__' . \Drupal::languageManager()->getCurrentLanguage()->id; + $suggestions[] = $hook . '__' . \Drupal::languageManager()->getCurrentLanguage()->getId(); } /** diff --git a/core/modules/taxonomy/src/Plugin/views/field/Language.php b/core/modules/taxonomy/src/Plugin/views/field/Language.php index 13e3d23..6345f5b 100644 --- a/core/modules/taxonomy/src/Plugin/views/field/Language.php +++ b/core/modules/taxonomy/src/Plugin/views/field/Language.php @@ -22,7 +22,7 @@ class Language extends Taxonomy { public function render(ResultRow $values) { $value = $this->getValue($values); $language = language_load($value); - $value = $language ? $language->name : ''; + $value = $language ? $language->getName() : ''; return $this->renderLink($this->sanitizeValue($value), $values); } diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index 58d198d..cfef112 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -33,7 +33,7 @@ public function form(array $form, array &$form_state) { '#type' => 'language_select', '#title' => $this->t('Language'), '#languages' => LanguageInterface::STATE_ALL, - '#default_value' => $term->getUntranslated()->language()->id, + '#default_value' => $term->getUntranslated()->language()->getId(), '#access' => !empty($language_configuration['language_show']), ); diff --git a/core/modules/taxonomy/src/Tests/TermLanguageTest.php b/core/modules/taxonomy/src/Tests/TermLanguageTest.php index 256a0a0..3da8b1b 100644 --- a/core/modules/taxonomy/src/Tests/TermLanguageTest.php +++ b/core/modules/taxonomy/src/Tests/TermLanguageTest.php @@ -63,7 +63,7 @@ function testTermLanguage() { $this->drupalPostForm(NULL, $edit, t('Save')); $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']); $term = reset($terms); - $this->assertEqual($term->language()->id, $edit['langcode'], 'The term contains the correct langcode.'); + $this->assertEqual($term->language()->getId(), $edit['langcode'], 'The term contains the correct langcode.'); // Check if on the edit page the language is correct. $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); @@ -103,10 +103,10 @@ function testDefaultTermLanguage() { // Change the default language of the site and check if the default terms // language is still correctly selected. $old_default = \Drupal::languageManager()->getDefaultLanguage(); - $old_default->default = FALSE; + $old_default->setDefault(FALSE); language_save($old_default); $new_default = \Drupal::languageManager()->getLanguage('cc'); - $new_default->default = TRUE; + $new_default->setDefault(TRUE); language_save($new_default); $edit = array( 'default_language[langcode]' => 'site_default', diff --git a/core/modules/taxonomy/src/Tests/TokenReplaceTest.php b/core/modules/taxonomy/src/Tests/TokenReplaceTest.php index caf23c4..f2e72f41 100644 --- a/core/modules/taxonomy/src/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/src/Tests/TokenReplaceTest.php @@ -96,7 +96,7 @@ function testTaxonomyTokenReplacement() { $tests['[term:vocabulary:name]'] = String::checkPlain($this->vocabulary->name); foreach ($tests as $input => $expected) { - $output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->id)); + $output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->getId())); $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input))); } @@ -116,7 +116,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->id)); + $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->getId())); $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input))); } @@ -127,7 +127,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->id, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy term token %token replaced.', array('%token' => $input))); } @@ -143,7 +143,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->id)); + $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId())); $this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', array('%token' => $input))); } @@ -152,7 +152,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->id, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy vocabulary token %token replaced.', array('%token' => $input))); } } diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index fde291e..8c393ad 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -781,7 +781,7 @@ function taxonomy_build_node_index($node) { $field_name = $field->getName(); if ($field->getType() == 'taxonomy_term_reference') { 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; } diff --git a/core/modules/text/src/Tests/TextWithSummaryItemTest.php b/core/modules/text/src/Tests/TextWithSummaryItemTest.php index 72d6aae..1f37e04 100644 --- a/core/modules/text/src/Tests/TextWithSummaryItemTest.php +++ b/core/modules/text/src/Tests/TextWithSummaryItemTest.php @@ -7,6 +7,7 @@ namespace Drupal\text\Tests; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\field\Tests\FieldUnitTestBase; diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 131a1a5..82e2282 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -375,7 +375,7 @@ function toolbar_toolbar() { // toolbar_subtrees route. We provide the JavaScript requesting that JSONP // script here with the hash parameter that is needed for that route. // @see toolbar_subtrees_jsonp() - $langcode = \Drupal::languageManager()->getCurrentLanguage()->id; + $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); $menu['toolbar_administration']['#attached']['js'][] = array( 'type' => 'setting', 'data' => array('toolbar' => array( diff --git a/core/modules/update/update.fetch.inc b/core/modules/update/update.fetch.inc index 4995d8e..f65967c 100644 --- a/core/modules/update/update.fetch.inc +++ b/core/modules/update/update.fetch.inc @@ -110,7 +110,7 @@ function _update_cron_notify() { if (!empty($params)) { $notify_list = $update_config->get('notification.emails'); if (!empty($notify_list)) { - $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id; + $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); foreach ($notify_list as $target) { if ($target_user = user_load_by_mail($target)) { $target_langcode = $target_user->getPreferredLangcode(); diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php index f4f718b..eaaa5d2 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -245,9 +245,9 @@ public function form(array $form, array &$form_state) { ); } - $user_preferred_langcode = $register ? $language_interface->id : $account->getPreferredLangcode(); + $user_preferred_langcode = $register ? $language_interface->getId() : $account->getPreferredLangcode(); - $user_preferred_admin_langcode = $register ? $language_interface->id : $account->getPreferredAdminLangcode(); + $user_preferred_admin_langcode = $register ? $language_interface->getId() : $account->getPreferredAdminLangcode(); // Is the user preferred language added? $user_language_added = FALSE; diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index 3cc77b7..c405fed 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -380,10 +380,10 @@ function getPreferredLangcode($default = NULL) { $language_list = language_list(); $preferred_langcode = $this->get('preferred_langcode')->value; if (!empty($preferred_langcode) && isset($language_list[$preferred_langcode])) { - return $language_list[$preferred_langcode]->id; + return $language_list[$preferred_langcode]->getId(); } else { - return $default ? $default : language_default()->id; + return $default ? $default : language_default()->getId(); } } @@ -394,10 +394,10 @@ function getPreferredAdminLangcode($default = NULL) { $language_list = language_list(); $preferred_langcode = $this->get('preferred_admin_langcode')->value; if (!empty($preferred_langcode) && isset($language_list[$preferred_langcode])) { - return $language_list[$preferred_langcode]->id; + return $language_list[$preferred_langcode]->getId(); } else { - return $default ? $default : language_default()->id; + return $default ? $default : language_default()->getId(); } } diff --git a/core/modules/user/src/Form/UserPasswordForm.php b/core/modules/user/src/Form/UserPasswordForm.php index 672dc11..fa04c19 100644 --- a/core/modules/user/src/Form/UserPasswordForm.php +++ b/core/modules/user/src/Form/UserPasswordForm.php @@ -127,7 +127,7 @@ public function validateForm(array &$form, array &$form_state) { * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - $langcode = $this->languageManager->getCurrentLanguage()->id; + $langcode = $this->languageManager->getCurrentLanguage()->getId(); $account = $form_state['values']['account']; // Mail one time login URL and instructions using current language. diff --git a/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php index f2c99fe..623dac6 100644 --- a/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php +++ b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php @@ -36,7 +36,7 @@ public function getLangcode(Request $request = NULL) { // User preference (only for authenticated users). if ($this->languageManager && $this->currentUser->isAuthenticated()) { $preferred_langcode = $this->currentUser->getPreferredLangcode(); - $default_langcode = $this->languageManager->getDefaultLanguage()->id; + $default_langcode = $this->languageManager->getDefaultLanguage()->getId(); $languages = $this->languageManager->getLanguages(); if (!empty($preferred_langcode) && $preferred_langcode != $default_langcode && isset($languages[$preferred_langcode])) { $langcode = $preferred_langcode; diff --git a/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php index cc0bfb5..89fede5 100644 --- a/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php +++ b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php @@ -82,7 +82,7 @@ public function getLangcode(Request $request = NULL) { // User preference (only for authenticated users). if ($this->languageManager && $this->currentUser->isAuthenticated() && $this->isAdminPath($request)) { $preferred_admin_langcode = $this->currentUser->getPreferredAdminLangcode(); - $default_langcode = $this->languageManager->getDefaultLanguage()->id; + $default_langcode = $this->languageManager->getDefaultLanguage()->getId(); $languages = $this->languageManager->getLanguages(); if (!empty($preferred_admin_langcode) && $preferred_admin_langcode != $default_langcode && isset($languages[$preferred_admin_langcode])) { $langcode = $preferred_admin_langcode; diff --git a/core/modules/user/src/Tests/UserInstallTest.php b/core/modules/user/src/Tests/UserInstallTest.php index 9fdb8db..4b9bb3d 100644 --- a/core/modules/user/src/Tests/UserInstallTest.php +++ b/core/modules/user/src/Tests/UserInstallTest.php @@ -54,8 +54,8 @@ public function testUserInstall() { // Test that the anonymous and administrators languages are equal to the // site's default language. - $this->assertEqual($anon->langcode, \Drupal::languageManager()->getDefaultLanguage()->id); - $this->assertEqual($admin->langcode, \Drupal::languageManager()->getDefaultLanguage()->id); + $this->assertEqual($anon->langcode, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Anon user language is the default.'); + $this->assertEqual($admin->langcode, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Admin user language is the default.'); // Test that the administrator is active. $this->assertEqual($admin->status, 1); diff --git a/core/modules/user/src/Tests/UserLanguageCreationTest.php b/core/modules/user/src/Tests/UserLanguageCreationTest.php index dbf80e4..2360b7b 100644 --- a/core/modules/user/src/Tests/UserLanguageCreationTest.php +++ b/core/modules/user/src/Tests/UserLanguageCreationTest.php @@ -69,7 +69,7 @@ function testLocalUserCreation() { $user = user_load_by_name($username); $this->assertEqual($user->getPreferredLangcode(), $langcode, 'New user has correct preferred language set.'); - $this->assertEqual($user->language()->id, $langcode, 'New user has correct profile language set.'); + $this->assertEqual($user->language()->getId(), $langcode, 'New user has correct profile language set.'); // Register a new user and check if the language selector is hidden. $this->drupalLogout(); @@ -87,7 +87,7 @@ function testLocalUserCreation() { $user = user_load_by_name($username); $this->assertEqual($user->getPreferredLangcode(), $langcode, 'New user has correct preferred language set.'); - $this->assertEqual($user->language()->id, $langcode, 'New user has correct profile language set.'); + $this->assertEqual($user->language()->getId(), $langcode, 'New user has correct profile language set.'); // Test if the admin can use the language selector and if the // correct language is was saved. diff --git a/core/modules/user/src/Tests/UserRegistrationTest.php b/core/modules/user/src/Tests/UserRegistrationTest.php index 0a6916c..dd7504b 100644 --- a/core/modules/user/src/Tests/UserRegistrationTest.php +++ b/core/modules/user/src/Tests/UserRegistrationTest.php @@ -188,8 +188,8 @@ function testRegistrationDefaultValues() { $this->assertTrue(($new_user->getCreatedTime() > REQUEST_TIME - 20 ), 'Correct creation time.'); $this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.'); $this->assertEqual($new_user->getTimezone(), $config_system_date->get('timezone.default'), 'Correct time zone field.'); - $this->assertEqual($new_user->langcode->value, \Drupal::languageManager()->getDefaultLanguage()->id, 'Correct language field.'); - $this->assertEqual($new_user->preferred_langcode->value, \Drupal::languageManager()->getDefaultLanguage()->id, 'Correct preferred language field.'); + $this->assertEqual($new_user->langcode->value, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Correct language field.'); + $this->assertEqual($new_user->preferred_langcode->value, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Correct preferred language field.'); $this->assertEqual($new_user->init->value, $mail, 'Correct init field.'); } diff --git a/core/modules/user/src/Tests/UserRoleAdminTest.php b/core/modules/user/src/Tests/UserRoleAdminTest.php index 0ddfa73..04361b2 100644 --- a/core/modules/user/src/Tests/UserRoleAdminTest.php +++ b/core/modules/user/src/Tests/UserRoleAdminTest.php @@ -32,7 +32,7 @@ function setUp() { */ function testRoleAdministration() { $this->drupalLogin($this->admin_user); - $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id; + $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); // Test presence of tab. $this->drupalGet('admin/people/permissions'); $tabs = $this->xpath('//ul[@class=:classes and //a[contains(., :text)]]', array( diff --git a/core/modules/user/src/Tests/UserTokenReplaceTest.php b/core/modules/user/src/Tests/UserTokenReplaceTest.php index 1f8f023..5e76499 100644 --- a/core/modules/user/src/Tests/UserTokenReplaceTest.php +++ b/core/modules/user/src/Tests/UserTokenReplaceTest.php @@ -67,17 +67,17 @@ function testUserTokenReplacement() { $tests['[user:mail]'] = String::checkPlain($account->getEmail()); $tests['[user:url]'] = url("user/" . $account->id(), $url_options); $tests['[user:edit-url]'] = url("user/" . $account->id() . "/edit", $url_options); - $tests['[user:last-login]'] = format_date($account->getLastLoginTime(), 'medium', '', NULL, $language_interface->id); - $tests['[user:last-login:short]'] = format_date($account->getLastLoginTime(), 'short', '', NULL, $language_interface->id); - $tests['[user:created]'] = format_date($account->getCreatedTime(), 'medium', '', NULL, $language_interface->id); - $tests['[user:created:short]'] = format_date($account->getCreatedTime(), 'short', '', NULL, $language_interface->id); + $tests['[user:last-login]'] = format_date($account->getLastLoginTime(), 'medium', '', NULL, $language_interface->getId()); + $tests['[user:last-login:short]'] = format_date($account->getLastLoginTime(), 'short', '', NULL, $language_interface->getId()); + $tests['[user:created]'] = format_date($account->getCreatedTime(), 'medium', '', NULL, $language_interface->getId()); + $tests['[user:created:short]'] = format_date($account->getCreatedTime(), 'short', '', NULL, $language_interface->getId()); $tests['[current-user:name]'] = String::checkPlain(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->id)); + $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->getId())); $this->assertEqual($output, $expected, format_string('Sanitized user token %token replaced.', array('%token' => $input))); } @@ -87,7 +87,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->id, 'sanitize' => FALSE)); + $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE)); $this->assertEqual($output, $expected, format_string('Unsanitized user token %token replaced.', array('%token' => $input))); } @@ -99,7 +99,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->id, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); + $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->getId(), '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.install b/core/modules/user/user.install index eca1692..134c251 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -67,7 +67,7 @@ function user_install() { $storage = \Drupal::entityManager()->getStorage('user'); // @todo Rely on the default value for langcode in // https://drupal.org/node/1966436 - $langcode = \Drupal::languageManager()->getDefaultLanguage()->id; + $langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); // Insert a row for the anonymous user. $storage ->create(array( diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 14edc2a..36e1325 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1492,7 +1492,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, \Drupal::languageManager()->getDefaultLanguage()->id, $params); + drupal_mail('user', 'register_pending_approval_admin', $site_mail, \Drupal::languageManager()->getDefaultLanguage()->getId(), $params); } } return empty($mail) ? NULL : $mail['result']; diff --git a/core/modules/views/src/Entity/Render/DefaultLanguageRenderer.php b/core/modules/views/src/Entity/Render/DefaultLanguageRenderer.php index 18875f5..2e99c12 100644 --- a/core/modules/views/src/Entity/Render/DefaultLanguageRenderer.php +++ b/core/modules/views/src/Entity/Render/DefaultLanguageRenderer.php @@ -24,7 +24,7 @@ class DefaultLanguageRenderer extends RendererBase { * A language code. */ protected function getLangcode(ResultRow $row) { - return $row->_entity->getUntranslated()->language()->id; + return $row->_entity->getUntranslated()->language()->getId(); } } diff --git a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php index 9d22eb4..1123fbc 100644 --- a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php @@ -293,7 +293,7 @@ public function generateResultsKey() { 'build_info' => $build_info, 'roles' => $user->getRoles(), 'super-user' => $user->id() == 1, // special caching for super user. - 'langcode' => \Drupal::languageManager()->getCurrentLanguage()->id, + 'langcode' => \Drupal::languageManager()->getCurrentLanguage()->getId(), 'base_url' => $GLOBALS['base_url'], ); foreach (array('exposed_info', 'page', 'sort', 'order', 'items_per_page', 'offset') as $key) { @@ -322,7 +322,7 @@ public function generateOutputKey() { 'roles' => $user->getRoles(), 'super-user' => $user->id() == 1, // special caching for super user. 'theme' => $GLOBALS['theme'], - 'langcode' => \Drupal::languageManager()->getCurrentLanguage()->id, + 'langcode' => \Drupal::languageManager()->getCurrentLanguage()->getId(), 'base_url' => $GLOBALS['base_url'], ); diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index cecfcc1..660bf7a 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -159,7 +159,7 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio $skip_cache = \Drupal::config('views.settings')->get('skip_cache'); if (empty($view->editing) || !$skip_cache) { - $cid = 'views:unpack_options:' . hash('sha256', serialize(array($this->options, $options))) . ':' . \Drupal::languageManager()->getCurrentLanguage()->id; + $cid = 'views:unpack_options:' . hash('sha256', serialize(array($this->options, $options))) . ':' . \Drupal::languageManager()->getCurrentLanguage()->getId(); if (empty(static::$unpackOptions[$cid])) { $cache = \Drupal::cache('data')->get($cid); if (!empty($cache->data)) { diff --git a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php index 8752531..57e2516 100644 --- a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php +++ b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php @@ -634,7 +634,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()->id, + 'langcode' => language_default()->getId(), ); $view = entity_create('view', $values); diff --git a/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php b/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php index 35c8c61..9ff4e1d 100644 --- a/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php +++ b/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php @@ -64,7 +64,7 @@ protected function setUp() { // The node.view route must exist when nodes are rendered. $this->container->get('router.builder')->rebuild(); - $this->langcodes = array(\Drupal::languageManager()->getDefaultLanguage()->id); + $this->langcodes = array(\Drupal::languageManager()->getDefaultLanguage()->getId()); for ($i = 0; $i < 2; $i++) { $langcode = 'l' . $i; $this->langcodes[] = $langcode; diff --git a/core/modules/views/src/ViewsData.php b/core/modules/views/src/ViewsData.php index bd65aa8..82b3c1b 100644 --- a/core/modules/views/src/ViewsData.php +++ b/core/modules/views/src/ViewsData.php @@ -108,7 +108,7 @@ public function __construct(CacheBackendInterface $cache_backend, ConfigFactoryI $this->moduleHandler = $module_handler; $this->languageManager = $language_manager; - $this->langcode = $this->languageManager->getCurrentLanguage()->id; + $this->langcode = $this->languageManager->getCurrentLanguage()->getId(); $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 ecc9f72..f00e6bb 100644 --- a/core/modules/views/views.api.php +++ b/core/modules/views/views.api.php @@ -343,8 +343,8 @@ function hook_views_query_substitutions(ViewExecutable $view) { return array( '***CURRENT_VERSION***' => \Drupal::VERSION, '***CURRENT_TIME***' => REQUEST_TIME, - '***CURRENT_LANGUAGE***' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id, - '***DEFAULT_LANGUAGE***' => \Drupal::languageManager()->getDefaultLanguage()->id, + '***CURRENT_LANGUAGE***' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(), + '***DEFAULT_LANGUAGE***' => \Drupal::languageManager()->getDefaultLanguage()->getId(), ); } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index cb9024b..6bd008e 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -519,7 +519,7 @@ function views_language_list($field = 'name', $flags = LanguageInterface::STATE_ $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; } diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 7d1060c..f7b5b99 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -967,7 +967,7 @@ function template_preprocess_views_view_rss(&$variables) { $variables['link'] = check_url(url($path, $url_options)); } - $variables['langcode'] = String::checkPlain(\Drupal::languageManager()->getCurrentLanguage()->id); + $variables['langcode'] = String::checkPlain(\Drupal::languageManager()->getCurrentLanguage()->getId()); $variables['namespaces'] = new Attribute($style->namespaces); $variables['items'] = $items; $variables['channel_elements'] = format_xml_elements($style->channel_elements); diff --git a/core/modules/views/views.views_execution.inc b/core/modules/views/views.views_execution.inc index 96b5006..1c4f5bc 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***' => \Drupal::VERSION, '***CURRENT_TIME***' => REQUEST_TIME, - '***CURRENT_LANGUAGE***' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id, - '***DEFAULT_LANGUAGE***' => \Drupal::languageManager()->getDefaultLanguage()->id, + '***CURRENT_LANGUAGE***' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(), + '***DEFAULT_LANGUAGE***' => \Drupal::languageManager()->getDefaultLanguage()->getId(), ); } diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh old mode 100755 new mode 100644 diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index c65883c..841dd8d 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -121,10 +121,14 @@ protected function setUp() { $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $language = $this->getMock('Drupal\Core\Language\LanguageInterface'); + $language->expects($this->any()) + ->method('getId') + ->will($this->returnValue('en')); $this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface'); $this->languageManager->expects($this->any()) ->method('getCurrentLanguage') - ->will($this->returnValue((object) array('id' => 'en'))); + ->will($this->returnValue($language)); $this->languageManager->expects($this->any()) ->method('getLanguages') ->will($this->returnValue(array('en' => (object) array('id' => 'en')))); @@ -974,9 +978,13 @@ public function testGetTranslationFromContext() { $entity->expects($this->exactly(2)) ->method('getUntranslated') ->will($this->returnValue($entity)); + $language = $this->getMock('\Drupal\Core\Language\LanguageInterface'); + $language->expects($this->any()) + ->method('getId') + ->will($this->returnValue('en')); $entity->expects($this->exactly(2)) ->method('language') - ->will($this->returnValue((object) array('id' => 'en'))); + ->will($this->returnValue($language)); $entity->expects($this->exactly(2)) ->method('hasTranslation') ->will($this->returnValueMap(array( @@ -1021,7 +1029,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') diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php index 3ecc8de..e5bae04 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php @@ -239,7 +239,7 @@ public function testAccess() { * @covers ::language */ public function testLanguage() { - $this->assertSame('en', $this->entity->language()->id); + $this->assertSame('en', $this->entity->language()->getId()); } /** diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php index 6b0c34e..95fb1c5 100644 --- 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; diff --git a/core/tests/Drupal/Tests/Core/Utility/TokenTest.php b/core/tests/Drupal/Tests/Core/Utility/TokenTest.php index 2f67a7b..ade5855 100644 --- a/core/tests/Drupal/Tests/Core/Utility/TokenTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/TokenTest.php @@ -83,7 +83,7 @@ public function testGetInfo() { ); $language = $this->getMock('\Drupal\Core\Language\Language'); - $language->id = $this->randomName(); + $language->setId($this->randomName()); $this->languageManager->expects($this->once()) ->method('getCurrentLanguage') @@ -96,7 +96,7 @@ public function testGetInfo() { ->method('get'); $this->cache->expects($this->once()) ->method('set') - ->with('token_info:' . $language->id, $token_info); + ->with('token_info:' . $language->getId(), $token_info); $this->moduleHandler->expects($this->once()) ->method('invokeAll')