Loading core/modules/content_translation/src/Controller/ContentTranslationController.php +1 −0 Original line number Diff line number Diff line Loading @@ -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 Loading core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php +33 −8 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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', Loading @@ -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'); } /** Loading Loading @@ -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); } } Loading
core/modules/content_translation/src/Controller/ContentTranslationController.php +1 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php +33 −8 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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', Loading @@ -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'); } /** Loading Loading @@ -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); } }