Commit 66762a53 authored by catch's avatar catch
Browse files

Issue #2340667 by YesCT, Pedro Lozano, alexpott, martin107: Protect...

Issue #2340667 by YesCT, Pedro Lozano, alexpott, martin107: Protect Drupal\Core\Language\Language::id, and use getId().
parent 51c10124
......@@ -752,7 +752,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.
......@@ -1525,7 +1525,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);
......
......@@ -1006,7 +1006,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
......
......@@ -719,7 +719,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'],
......@@ -731,7 +731,7 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) {
}
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->getWeight());
}
......
......@@ -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);
......
......@@ -189,7 +189,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);
return $entity;
......
......@@ -133,7 +133,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.
......
......@@ -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.
......
......@@ -475,7 +475,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)) {
......
......@@ -91,7 +91,7 @@ public function getFormLangcode(FormStateInterface $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->set('langcode', $this->entityManager->getTranslationFromContext($this->entity)->language()->id);
$form_state->set('langcode', $this->entityManager->getTranslationFromContext($this->entity)->language()->getId());
}
return $form_state->get('langcode');
}
......@@ -100,7 +100,7 @@ public function getFormLangcode(FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function isDefaultFormLangcode(FormStateInterface $form_state) {
return $this->getFormLangcode($form_state) == $this->entity->getUntranslated()->language()->id;
return $this->getFormLangcode($form_state) == $this->entity->getUntranslated()->language()->getId();
}
/**
......
......@@ -335,7 +335,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;
}
......@@ -433,7 +433,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;
}
......@@ -541,7 +541,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;
}
......@@ -680,7 +680,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;
}
......@@ -721,7 +721,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;
......@@ -783,7 +783,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
......@@ -794,7 +794,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) {
......@@ -849,7 +849,7 @@ protected function getAllDisplayModesByEntityType($display_type) {
if (!isset($this->displayModeInfo[$display_type])) {
$key = 'entity_' . $display_type . '_info';
$entity_type_id = 'entity_' . $display_type;
$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;
}
......
......@@ -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(
......
......@@ -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
......
......@@ -1112,8 +1112,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;
}
......@@ -1199,7 +1199,7 @@ protected function loadFieldItems(array $entities) {
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.
......@@ -1275,7 +1275,7 @@ protected function saveFieldItems(EntityInterface $entity, $update = TRUE) {
$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());
$table_mapping = $this->getTableMapping();
......
......@@ -94,7 +94,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.
......
......@@ -41,7 +41,7 @@ class Language implements LanguageInterface {
*
* @var string
*/
public $id = '';
protected $id = '';
/**
* The direction, left-to-right, or right-to-left.
......
......@@ -134,7 +134,7 @@ 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->getWeight());
}
......
......@@ -100,7 +100,7 @@ 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['lang'] = $language_interface->getId();
$html_attributes['dir'] = $language_interface->getDirection();
$this->setDefaultMetaTags($page);
......
......@@ -157,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])) {
......@@ -191,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,
......
......@@ -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;
......
......@@ -170,7 +170,7 @@ public static function processMachineName(&$element, FormStateInterface $form_st
'machineName' => array(
'#' . $source['#id'] => $element['#machine_name'],
),
'langcode' => $language->id,
'langcode' => $language->getId(),
),
);
$element['#attached']['library'][] = 'core/drupal.machine-name';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment