You are here

protected function LayoutBuilderAtBase::addEntityTranslation in Layout Builder Asymmetric Translation 8.2

Adds an entity translation.

Parameters

$copy: Whether to copy the blocks or not.

$target: The target of the langcode.

$source_language: Which source language to use, if applicable.

2 calls to LayoutBuilderAtBase::addEntityTranslation()
LayoutBuilderAtReplicateTest::testAsymmetricTranslationWithReplicate in tests/src/Functional/LayoutBuilderAtReplicateTest.php
Tests that layout overrides have copied blocks.
LayoutBuilderAtTranslationTest::testAsymmetricTranslation in tests/src/Functional/LayoutBuilderAtTranslationTest.php
Tests that layout overrides have different blocks.

File

tests/src/Functional/LayoutBuilderAtBase.php, line 257

Class

LayoutBuilderAtBase
Base class for Layout Builder Asymmetric Translations.

Namespace

Drupal\Tests\layout_builder_at\Functional

Code

protected function addEntityTranslation($copy = FALSE, $target = 2, $source_language = NULL) {
  $user = $this->loggedInUser;
  $this
    ->drupalLogin($this->translator);
  $add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
    $this->entityTypeId => $this->entity
      ->id(),
    'source' => $this->langcodes[0],
    'target' => $this->langcodes[$target],
  ]);
  $this
    ->drupalGet($add_translation_url);
  if ($source_language) {
    $this
      ->drupalPostForm(NULL, [
      'source_langcode[source]' => $source_language,
    ], 'Change');
  }
  $edit = [
    "{$this->fieldName}[0][value]" => 'The translated field value',
  ];
  if ($copy) {
    $this
      ->assertText('Copy blocks into translation');
    $edit['layout_builder__layout[value]'] = TRUE;
  }
  elseif (isset($copy)) {
    $this
      ->assertNoText('Copy blocks into translation');
  }
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $this
    ->drupalLogin($user);
}