From ee23a992147ef712a2ecda54ce5fa8ccd82df51a Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Fri, 17 Mar 2023 19:04:31 +0200 Subject: [PATCH 1/4] EWPP-3180: Fix translatability of fields in FieldListPattern formatter. --- .../FieldGroupFormatter/FieldListPattern.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/oe_theme_helper/src/Plugin/field_group/FieldGroupFormatter/FieldListPattern.php b/modules/oe_theme_helper/src/Plugin/field_group/FieldGroupFormatter/FieldListPattern.php index a5e426fed..c40f02d23 100755 --- a/modules/oe_theme_helper/src/Plugin/field_group/FieldGroupFormatter/FieldListPattern.php +++ b/modules/oe_theme_helper/src/Plugin/field_group/FieldGroupFormatter/FieldListPattern.php @@ -34,9 +34,18 @@ protected function getFields(array &$element, $rendering_object): array { $fields = []; foreach (Element::children($element) as $field_name) { + $label = $element[$field_name]['#title'] ?? ''; + // By some conditions label of some fields could be passed not yet + // translated. It can be related to field_group implementation. + // @todo Investigate why some field labels are translated and some is not. + if (!empty($label) && is_string($label)) { + // @codingStandardsIgnoreStart + $label = $this->t($label); + // @codingStandardsIgnoreEnd + } // Assign field label and content to the pattern's fields. $fields['items'][] = [ - 'label' => $element[$field_name]['#title'] ?? '', + 'label' => $label, 'body' => [ '#label_display' => 'hidden', ] + $element[$field_name], From 818dce2893a6db0847c6da39301134f1ba6c55fa Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Mon, 20 Mar 2023 10:26:45 +0200 Subject: [PATCH 2/4] EWPP-3180: Use latest master branch of oe_multilingual. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a295fa06d..89544619e 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "openeuropa/oe_corporate_blocks": "^4.11", "openeuropa/oe_corporate_countries": "^2.0.0-alpha6", "openeuropa/oe_media": "^1.22", - "openeuropa/oe_multilingual": "^1.13", + "openeuropa/oe_multilingual": "dev-master", "openeuropa/oe_paragraphs": "^1.17", "openeuropa/oe_search": "^1.9", "openeuropa/oe_webtools": "^1.21", From 7a8c871e8028ed5974824c0fb41f9e07308369a6 Mon Sep 17 00:00:00 2001 From: Sergii Pavlenko Date: Mon, 20 Mar 2023 12:06:17 +0200 Subject: [PATCH 3/4] EWPP-3180: Fix failed tests related to changes in language switcher services. --- .../src/Kernel/MultilingualAbstractKernelTestBase.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/src/Kernel/MultilingualAbstractKernelTestBase.php b/tests/src/Kernel/MultilingualAbstractKernelTestBase.php index 9196bac26..6c4bcbafb 100644 --- a/tests/src/Kernel/MultilingualAbstractKernelTestBase.php +++ b/tests/src/Kernel/MultilingualAbstractKernelTestBase.php @@ -4,7 +4,10 @@ namespace Drupal\Tests\oe_theme\Kernel; +use Drupal\Core\Routing\RouteObjectInterface; use Drupal\locale\SourceString; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Route; /** * Base class for multilingual tests. @@ -56,6 +59,13 @@ protected function setUp(): void { $this->container->get('module_handler')->loadInclude('oe_multilingual', 'install'); oe_multilingual_install(FALSE); + // In order to make it possible correctly render the language switcher block + // we have to provide the current route explicitly. + $request = Request::create('/'); + $request->attributes->set(RouteObjectInterface::ROUTE_NAME, ''); + $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/')); + $this->container->get('request_stack')->push($request); + // Rebuild the container in order to make sure tests pass. // @todo fix test setup so that we can get rid of this line. $this->container->get('kernel')->rebuildContainer(); From 621c65862f86ffcb72b202db8a0ccacf78ee1be9 Mon Sep 17 00:00:00 2001 From: nagyad Date: Mon, 20 Mar 2023 12:21:40 +0100 Subject: [PATCH 4/4] EWPP-3180: Ensure that user has access to see content in tests. --- tests/src/Kernel/ContentLanguageSwitcherTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/src/Kernel/ContentLanguageSwitcherTest.php b/tests/src/Kernel/ContentLanguageSwitcherTest.php index 251599e3f..e70334b86 100644 --- a/tests/src/Kernel/ContentLanguageSwitcherTest.php +++ b/tests/src/Kernel/ContentLanguageSwitcherTest.php @@ -6,6 +6,7 @@ use Drupal\node\Entity\Node; use Drupal\Tests\oe_theme\Traits\RequestTrait; +use Drupal\Tests\user\Traits\UserCreationTrait; use Symfony\Component\DomCrawler\Crawler; /** @@ -16,6 +17,7 @@ class ContentLanguageSwitcherTest extends MultilingualAbstractKernelTestBase { use RequestTrait; + use UserCreationTrait; /** * Modules to enable. @@ -34,6 +36,7 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installSchema('node', 'node_access'); + $this->container->get('current_user')->setAccount($this->createUser(['access content'])); } /** @@ -43,6 +46,7 @@ public function testLanguageSwitcherRendering(): void { $node = Node::create([ 'title' => 'Hello, world!', 'type' => 'oe_demo_translatable_page', + 'status' => 1, ]); /** @var \Drupal\Core\Entity\EntityInterface $translation */ $node->addTranslation('es', ['title' => '¡Hola mundo!'])->save();