summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-11-01 23:59:21 (GMT)
committerAlex Pott2015-11-01 23:59:21 (GMT)
commitb412acf2abdbc40a0b7f7c0b3508d51e0482cd6e (patch)
tree2169c0e14d07d2091fa97a68507675a42e2632c7
parent63935833b0a3ac2a6df22cf9e1c42af529fa674a (diff)
Issue #2453551 by mbovan, edurenye, Berdir, Saphyel, jhodgdon: TranslationLanguageRenderer tries to add langcode field to the view for entity types that have no langcode
-rw-r--r--core/modules/language/tests/language_test/config/optional/views.view.no_entity_translation_view.yml172
-rw-r--r--core/modules/language/tests/language_test/src/Entity/NoLanguageEntityTest.php3
-rw-r--r--core/modules/views/src/Entity/Render/RendererBase.php2
-rw-r--r--core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php21
-rw-r--r--core/modules/views/src/Tests/Entity/ViewNonTranslatableEntityTest.php51
5 files changed, 236 insertions, 13 deletions
diff --git a/core/modules/language/tests/language_test/config/optional/views.view.no_entity_translation_view.yml b/core/modules/language/tests/language_test/config/optional/views.view.no_entity_translation_view.yml
new file mode 100644
index 0000000..8e7ef45
--- /dev/null
+++ b/core/modules/language/tests/language_test/config/optional/views.view.no_entity_translation_view.yml
@@ -0,0 +1,172 @@
+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: { }
diff --git a/core/modules/language/tests/language_test/src/Entity/NoLanguageEntityTest.php b/core/modules/language/tests/language_test/src/Entity/NoLanguageEntityTest.php
index 5018784..8fda7fe 100644
--- a/core/modules/language/tests/language_test/src/Entity/NoLanguageEntityTest.php
+++ b/core/modules/language/tests/language_test/src/Entity/NoLanguageEntityTest.php
@@ -17,6 +17,9 @@ use Drupal\Core\Field\BaseFieldDefinition;
* @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 = {
diff --git a/core/modules/views/src/Entity/Render/RendererBase.php b/core/modules/views/src/Entity/Render/RendererBase.php
index 19f98c3..b8b242a 100644
--- a/core/modules/views/src/Entity/Render/RendererBase.php
+++ b/core/modules/views/src/Entity/Render/RendererBase.php
@@ -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;
diff --git a/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php b/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php
index c94243b..154d8f7 100644
--- a/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php
+++ b/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php
@@ -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);
}
}
diff --git a/core/modules/views/src/Tests/Entity/ViewNonTranslatableEntityTest.php b/core/modules/views/src/Tests/Entity/ViewNonTranslatableEntityTest.php
new file mode 100644
index 0000000..ca7f9c0
--- /dev/null
+++ b/core/modules/views/src/Tests/Entity/ViewNonTranslatableEntityTest.php
@@ -0,0 +1,51 @@
+<?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());
+ }
+
+}