Commit a805ce2d authored by alexpott's avatar alexpott

Issue #2450205 by Gábor Hojtsy, mrjmd, plach: Translation settings don't...

Issue #2450205 by Gábor Hojtsy, mrjmd, plach: Translation settings don't appear for node in standard
parent 40d57b3d
......@@ -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;
}
......
......@@ -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);
}
}
......@@ -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***');
......
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