View source
<?php
namespace Drupal\Tests\paragraphs\Functional\WidgetStable;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\paragraphs\Traits\ParagraphsLastEntityQueryTrait;
class ParagraphsTranslationsTest extends ParagraphsTestBase {
use ParagraphsLastEntityQueryTrait;
public static $modules = [
'node',
'paragraphs_test',
'paragraphs',
'field',
'field_ui',
'block',
'link',
'content_translation',
];
protected $visitorUser;
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('system_breadcrumb_block');
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('local_actions_block');
$this
->drupalPlaceBlock('page_title_block');
$this
->addParagraphedContentType('paragraphed_test', 'field_paragraphs', 'paragraphs');
ConfigurableLanguage::createFromLangcode('de')
->save();
$this
->loginAsAdmin([
'access administration pages',
'view all revisions',
'revert all revisions',
'administer nodes',
'bypass node access',
'administer content translation',
'translate any entity',
'create content translations',
'administer languages',
'administer content types',
'administer node form display',
'edit any paragraphed_test content',
'create paragraphed_test content',
'edit behavior plugin settings',
]);
$this->visitorUser = $this
->drupalCreateUser([
'access content',
'view all revisions',
]);
$this
->addParagraphsType('text_translatable');
$this
->addParagraphsType('text_untranslatable');
$this
->addParagraphsType('text_untranslatable_hide');
$this
->addParagraphsType('container');
$this
->addFieldtoParagraphType('text_translatable', 'field_text_translatable', 'text');
$this
->addFieldtoParagraphType('text_untranslatable', 'field_text_untranslatable', 'text');
$this
->addFieldtoParagraphType('text_untranslatable_hide', 'field_text_untranslatable_hide', 'text');
$this
->addParagraphsField('container', 'field_paragraphs', 'paragraph');
$this
->drupalGet('admin/config/regional/content-language');
$this
->assertSession()
->pageTextContains('Paragraph types that are used in moderated content requires non-translatable fields to be edited in the original language form and this must be checked.');
$edit = [
'entity_types[paragraph]' => TRUE,
'entity_types[node]' => TRUE,
'settings[node][paragraphed_test][translatable]' => TRUE,
'settings[node][paragraphed_test][fields][field_paragraphs]' => FALSE,
'settings[node][paragraphed_test][settings][language][language_alterable]' => TRUE,
'settings[paragraph][text_translatable][translatable]' => TRUE,
'settings[paragraph][text_untranslatable][translatable]' => TRUE,
'settings[paragraph][text_untranslatable_hide][translatable]' => TRUE,
'settings[paragraph][container][translatable]' => TRUE,
'settings[paragraph][text_translatable][settings][content_translation][untranslatable_fields_hide]' => TRUE,
'settings[paragraph][text_untranslatable][settings][content_translation][untranslatable_fields_hide]' => FALSE,
'settings[paragraph][text_untranslatable_hide][settings][content_translation][untranslatable_fields_hide]' => TRUE,
'settings[paragraph][container][settings][content_translation][untranslatable_fields_hide]' => TRUE,
'settings[paragraph][text_translatable][fields][field_text_translatable]' => TRUE,
'settings[paragraph][text_untranslatable][fields][field_text_untranslatable]' => FALSE,
'settings[paragraph][text_untranslatable_hide][fields][field_text_untranslatable_hide]' => FALSE,
'settings[paragraph][container][fields][field_paragraphs]' => FALSE,
];
$this
->submitForm($edit, 'Save configuration');
}
public function testUntranslatableAutoCollapse() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
$this
->drupalGet('node/add/paragraphed_test');
$page
->fillField('title[0][value]', 'Page 1 EN');
$page
->pressButton('Add text_translatable');
$page
->pressButton('Add text_untranslatable');
$page
->pressButton('Add text_untranslatable_hide');
$page
->pressButton('Add container');
$page
->fillField('field_paragraphs[0][subform][field_text_translatable][0][value]', 'Translate me EN');
$page
->fillField('field_paragraphs[1][subform][field_text_untranslatable][0][value]', 'Do not translate me EN');
$page
->fillField('field_paragraphs[2][subform][field_text_untranslatable_hide][0][value]', 'Do not translate me CLOSED EN');
$page
->pressButton('Save');
$assert_session
->pageTextContains('paragraphed_test Page 1 EN has been created.');
$host_node = $this
->getLastEntityOfType('node', TRUE);
$host_node_id = $host_node
->id();
$this
->drupalGet("/de/node/{$host_node_id}/translations/add/en/de");
$assert_session
->fieldExists('field_paragraphs[0][subform][field_text_translatable][0][value]');
$assert_session
->buttonExists('field_paragraphs_0_collapse');
$assert_session
->fieldNotExists('field_paragraphs[2][subform][field_text_untranslatable_hide][0][value]');
$assert_session
->buttonNotExists('field_paragraphs_2_collapse');
$assert_session
->buttonNotExists('field_paragraphs_2_edit');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Do not translate me CLOSED EN');
$assert_session
->buttonExists('field_paragraphs_1_collapse');
$assert_session
->fieldExists('field_paragraphs[1][subform][field_text_untranslatable][0][value]');
$page
->pressButton('field_paragraphs_1_collapse');
$assert_session
->fieldNotExists('field_paragraphs[1][subform][field_text_untranslatable][0][value]');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Do not translate me EN');
$assert_session
->buttonExists('field_paragraphs_1_edit');
$assert_session
->buttonExists('field_paragraphs_3_collapse');
$page
->pressButton('field_paragraphs_3_collapse');
$assert_session
->buttonExists('field_paragraphs_3_edit');
$this
->drupalGet('node/' . $host_node_id . '/edit');
$page
->pressButton('field_paragraphs_3_subform_field_paragraphs_text_translatable_add_more');
$page
->fillField('field_paragraphs[3][subform][field_paragraphs][0][subform][field_text_translatable][0][value]', 'Nested translate me EN');
$page
->pressButton('Save');
$this
->setParagraphsWidgetSettings('paragraphed_test', 'field_paragraphs', [
'edit_mode' => 'closed',
], 'paragraphs', 'node');
$this
->setParagraphsWidgetSettings('container', 'field_paragraphs', [
'edit_mode' => 'closed',
], 'paragraphs', 'paragraph');
$this
->drupalGet("/de/node/{$host_node_id}/translations/add/en/de");
$assert_session
->fieldExists('field_paragraphs[0][subform][field_text_translatable][0][value]');
$assert_session
->fieldExists('field_paragraphs[1][subform][field_text_untranslatable][0][value]');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Do not translate me CLOSED EN');
$assert_session
->fieldExists('field_paragraphs[3][subform][field_paragraphs][0][subform][field_text_translatable][0][value]');
$page
->fillField('field_paragraphs[0][subform][field_text_translatable][0][value]', 'Translate me DE');
$page
->fillField('field_paragraphs[3][subform][field_paragraphs][0][subform][field_text_translatable][0][value]', 'Nested translate me DE');
$page
->pressButton('field_paragraphs_collapse_all');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Translate me DE');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Do not translate me EN');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Do not translate me CLOSED EN');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Nested translate me DE');
$page
->pressButton('field_paragraphs_0_edit');
$page
->fillField('field_paragraphs[0][subform][field_text_translatable][0][value]', 'Translate me UPDATE DE');
$page
->pressButton('field_paragraphs_3_edit');
$assert_session
->fieldExists('field_paragraphs[3][subform][field_paragraphs][0][subform][field_text_translatable][0][value]');
$page
->pressButton('Save (this translation)');
$this
->drupalGet('de/node/' . $host_node_id . '/edit');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Translate me UPDATE DE');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Do not translate me EN');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Do not translate me CLOSED EN');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Nested translate me DE');
$page
->pressButton('field_paragraphs_edit_all');
$assert_session
->fieldExists('field_paragraphs[0][subform][field_text_translatable][0][value]');
$assert_session
->fieldExists('field_paragraphs[1][subform][field_text_untranslatable][0][value]');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Do not translate me CLOSED EN');
$assert_session
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Nested translate me DE');
$assert_session
->fieldNotExists('field_paragraphs[3][subform][field_paragraphs][0][subform][field_text_translatable][0][value]');
$page
->pressButton('field_paragraphs_3_subform_field_paragraphs_0_edit');
$assert_session
->fieldExists('field_paragraphs[3][subform][field_paragraphs][0][subform][field_text_translatable][0][value]');
}
}