From a805ce2d5054625e487da5ba33de78e7ec6c1577 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Mon, 16 Mar 2015 08:46:58 +0000 Subject: [PATCH] =?UTF-8?q?Issue=20#2450205=20by=20G=C3=A1bor=20Hojtsy,=20?= =?UTF-8?q?mrjmd,=20plach:=20Translation=20settings=20don't=20appear=20for?= =?UTF-8?q?=20node=20in=20standard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/display/DisplayPluginBase.php | 12 ++--- .../views/src/Tests/Plugin/DisplayTest.php | 49 +++++++++++++++++++ .../views_ui/src/Tests/ViewEditTest.php | 2 +- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 87bc22189424..5a4bda2f5a04 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -1619,7 +1619,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { break; case 'rendering_language': $form['#title'] .= $this->t('Rendering language'); - if ($this->isBaseTableTranslatable()) { + if (\Drupal::languageManager()->isMultilingual() && $this->isBaseTableTranslatable()) { $options = $this->buildRenderingLanguageOptions(); $form['rendering_language'] = array( '#type' => 'select', @@ -1630,7 +1630,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ); } else { - $form['rendering_language']['#markup'] = $this->t("You don't have translatable entity types."); + $form['rendering_language']['#markup'] = $this->t('The view is not based on a translatable entity type or the site is not multilingual.'); } break; case 'style': @@ -2613,13 +2613,7 @@ protected function isBaseTableTranslatable() { $views_data = Views::viewsData()->get($view_base_table); if (!empty($views_data['table']['entity type'])) { $entity_type_id = $views_data['table']['entity type']; - $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id); - - $base_table = $entity_type->getBaseTable(); - $data_table = $entity_type->getDataTable(); - $revision_table = $entity_type->getRevisionTable(); - $revision_data_table = $entity_type->getRevisionDataTable(); - return $entity_type->isTranslatable() && in_array($view_base_table, [$base_table, $data_table, $revision_table, $revision_data_table]); + return \Drupal::entityManager()->getDefinition($entity_type_id)->isTranslatable(); } return FALSE; } diff --git a/core/modules/views/src/Tests/Plugin/DisplayTest.php b/core/modules/views/src/Tests/Plugin/DisplayTest.php index f0eb43faaa1c..e22440352014 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayTest.php @@ -7,6 +7,7 @@ namespace Drupal\views\Tests\Plugin; +use Drupal\language\Entity\ConfigurableLanguage; use Drupal\views\Views; use Drupal\views_test_data\Plugin\views\display\DisplayTest as DisplayTestPlugin; @@ -346,4 +347,52 @@ public function testOutputIsEmpty() { $this->assertTrue($view->display_handler->outputIsEmpty(), 'Ensure the view output is marked as empty.'); } + /** + * Test translation rendering settings based on entity translatability. + */ + public function testTranslationSetting() { + \Drupal::service('module_installer')->install(['file']); + + // By default there should be no language settings. + $this->checkTranslationSetting(); + \Drupal::service('module_installer')->install(['language']); + + // Enabling the language module should not make a difference. + $this->checkTranslationSetting(); + + // Making the site multilingual should let translatable entity types support + // translation rendering. + ConfigurableLanguage::createFromLangcode('it')->save(); + $this->checkTranslationSetting(TRUE); + } + + /** + * Asserts a node and a file based view for the translation setting. + * + * The file based view should never expose that setting. The node based view + * should if the site is multilingual. + * + * @param bool $expected_node_translatability + * Whether the node based view should be expected to support translation + * settings. + */ + protected function checkTranslationSetting($expected_node_translatability = FALSE) { + $not_supported_text = 'The view is not based on a translatable entity type or the site is not multilingual.'; + $supported_text = 'All content that supports translations will be displayed in the selected language.'; + + $this->drupalGet('admin/structure/views/nojs/display/content/page_1/rendering_language'); + if ($expected_node_translatability) { + $this->assertNoText($not_supported_text); + $this->assertText($supported_text); + } + else { + $this->assertText($not_supported_text); + $this->assertNoText($supported_text); + } + + $this->drupalGet('admin/structure/views/nojs/display/files/page_1/rendering_language'); + $this->assertText($not_supported_text); + $this->assertNoText($supported_text); + } + } diff --git a/core/modules/views_ui/src/Tests/ViewEditTest.php b/core/modules/views_ui/src/Tests/ViewEditTest.php index 5ec8e3d2e51b..07d5bb283eed 100644 --- a/core/modules/views_ui/src/Tests/ViewEditTest.php +++ b/core/modules/views_ui/src/Tests/ViewEditTest.php @@ -135,7 +135,7 @@ public function testEditFormLanguageOptions() { $this->drupalGet($langcode_url); $this->assertResponse(200); if ($view_name == 'test_view') { - $this->assertText(t("You don't have translatable entity types.")); + $this->assertText(t('The view is not based on a translatable entity type or the site is not multilingual.')); } else { $this->assertFieldByName('rendering_language', '***LANGUAGE_entity_translation***'); -- GitLab