Commit 034eaaff authored by catch's avatar catch
Browse files

Issue #3549953 by idebr: No interface language switch links available on the...

Issue #3549953 by idebr: No interface language switch links available on the content translation 'add' form

(cherry picked from commit 24bcada2)
parent 73d74826
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -395,6 +395,7 @@ public function add(LanguageInterface $source, LanguageInterface $target, RouteM

    // @todo Exploit the upcoming hook_entity_prepare() when available.
    // See https://www.drupal.org/node/1810394.
    $entity = clone $entity;
    $this->prepareTranslation($entity, $source, $target);

    // @todo Provide a way to figure out the default form operation in
+33 −8
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

namespace Drupal\Tests\content_translation\Functional;

use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\content_translation\Traits\ContentTranslationTestTrait;
use Drupal\Tests\image\Kernel\ImageFieldCreationTrait;
use Drupal\Tests\node\Functional\NodeTestBase;
@@ -50,6 +51,14 @@ protected function setUp(): void {
      static::createLanguageFromLangcode($langcode);
    }
    $this->drupalPlaceBlock('local_tasks_block');

    // Enable translations for article.
    $this->enableContentTranslation('node', 'article');

    $this->rebuildContainer();

    $this->createImageField('field_image_field', 'node', 'article');

    $user = $this->drupalCreateUser([
      'administer site configuration',
      'administer nodes',
@@ -57,20 +66,13 @@ protected function setUp(): void {
      'edit any article content',
      'delete any article content',
      'administer content translation',
      'translate any entity',
      'translate article node',
      'create content translations',
      'administer languages',
      'administer content types',
      'administer node fields',
    ]);
    $this->drupalLogin($user);

    // Enable translations for article.
    $this->enableContentTranslation('node', 'article');

    $this->rebuildContainer();

    $this->createImageField('field_image_field', 'node', 'article');
  }

  /**
@@ -155,4 +157,27 @@ public function testTitleDoesNotChangesOnChangingLanguageWidgetAndTriggeringAjax
    $this->assertArrayNotHasKey('de', $translation_languages);
  }

  /**
   * Tests language switch links while translating content.
   */
  public function testLanguageSwitchLinks(): void {
    $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [
      'id' => 'test_language_block',
    ]);

    $this->drupalGet('node/add/article');
    $edit = [
      'title[0][value]' => 'english_title',
    ];
    $this->submitForm($edit, 'Save');

    // Create a translation in French.
    $this->clickLink('Translate');
    $language_switch_links = $this->xpath('//div[@id=:id]/ul/li', [':id' => 'block-test-language-block']);
    $this->assertCount(3, $language_switch_links);
    $this->clickLink('Add');
    $language_switch_links = $this->xpath('//div[@id=:id]/ul/li', [':id' => 'block-test-language-block']);
    $this->assertCount(3, $language_switch_links);
  }

}