Commit b412acf2 authored by alexpott's avatar alexpott

Issue #2453551 by mbovan, edurenye, Berdir, Saphyel, jhodgdon:...

Issue #2453551 by mbovan, edurenye, Berdir, Saphyel, jhodgdon: TranslationLanguageRenderer tries to add langcode field to the view for entity types that have no langcode
parent 63935833
langcode: en
status: true
dependencies:
module:
- language_test
id: no_entity_translation_view
label: 'No Entity Translation View'
module: views
description: ''
tag: ''
base_table: no_language_entity_test
base_field: id
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: none
options: { }
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: full
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ' Previous'
next: 'Next ›'
first: '« First'
last: 'Last »'
quantity: 9
style:
type: default
row:
type: fields
options:
default_field_elements: true
inline:
operations: operations
separator: ''
hide_empty: false
fields:
uuid:
id: uuid
table: no_language_entity_test
field: uuid
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: string
settings:
link_to_entity: false
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: no_language_entity_test
entity_field: uuid
plugin_id: field
filters: { }
sorts: { }
title: 'No Entity Translation View'
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
tags: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: no-entity-translation-view
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
tags: { }
......@@ -17,6 +17,9 @@
* @ContentEntityType(
* id = "no_language_entity_test",
* label = @Translation("Test entity without language support"),
* handlers = {
* "views_data" = "Drupal\entity_test\EntityTestViewsData"
* },
* base_table = "no_language_entity_test",
* persistent_cache = FALSE,
* entity_keys = {
......
......@@ -37,7 +37,7 @@ abstract class RendererBase implements CacheableDependencyInterface {
/**
* The type of the entity being rendered.
*
* @var string
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $entityType;
......
......@@ -27,21 +27,18 @@ class TranslationLanguageRenderer extends EntityTranslationRendererBase {
* {@inheritdoc}
*/
public function query(QueryPluginBase $query, $relationship = NULL) {
// There is no point in getting the language, in case the site is not
// multilingual.
if (!$this->languageManager->isMultilingual()) {
// In order to render in the translation language of the entity, we need
// to add the language code of the entity to the query. Skip if the site
// is not multilingual or the entity is not translatable.
if (!$this->languageManager->isMultilingual() || !$this->entityType->hasKey('langcode')) {
return;
}
// If the data table is defined, we use the translation language as render
// language, otherwise we fall back to the default entity language, which is
// stored in the revision table for revisionable entity types.
$langcode_key = $this->entityType->getKey('langcode');
foreach (array('data_table', 'revision_table', 'base_table') as $key) {
if ($table = $this->entityType->get($key)) {
$table_alias = $query->ensureTable($table, $relationship);
$this->langcodeAlias = $query->addField($table_alias, $langcode_key);
break;
}
$storage = \Drupal::entityManager()->getStorage($this->entityType->id());
if ($table = $storage->getTableMapping()->getFieldTableName($langcode_key)) {
$table_alias = $query->ensureTable($table, $relationship);
$this->langcodeAlias = $query->addField($table_alias, $langcode_key);
}
}
......
<?php
/**
* @file
* Contains \Drupal\views\Tests\Entity\ViewNonTranslatableEntityTest.
*/
namespace Drupal\views\Tests\Entity;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language_test\Entity\NoLanguageEntityTest;
use Drupal\simpletest\WebTestBase;
/**
* Tests the view creation of non-translatable entities.
*
* @group views
*/
class ViewNonTranslatableEntityTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'entity_test',
'content_translation',
'language_test',
'views_ui',
);
/**
* Tests displaying a view of non-translatable entities.
*/
public function testViewNoTranslatableEntity() {
// Add a new language.
ConfigurableLanguage::createFromLangcode('sr')->save();
// Create a non-translatable entity.
$no_language_entity = NoLanguageEntityTest::create();
$no_language_entity->save();
// Visit the view page and assert it is displayed properly.
$this->drupalGet('no-entity-translation-view');
$this->assertResponse(200);
$this->assertText('No Entity Translation View');
$this->assertText($no_language_entity->uuid());
}
}
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