Skip to content

Commit 005b67c

Browse files
author
René Hrdina
committed
feat: properly support translated info collection fields
1 parent 6cd0a40 commit 005b67c

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

bundle/EzPlatform/RepositoryForms/InformationCollectionMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class InformationCollectionMapper
2626
*/
2727
public function mapToFormData(Content $content, Location $location, ContentType $contentType)
2828
{
29-
$fields = $content->getFieldsByLanguage($content->contentInfo->mainLanguageCode);
29+
$fields = $content->getFieldsByLanguage();
3030

3131
$informationCollectionFields = [];
3232

lib/Handler.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use eZ\Publish\API\Repository\ContentTypeService;
66
use eZ\Publish\API\Repository\Values\Content\Content;
77
use eZ\Publish\API\Repository\Values\Content\Location;
8+
use eZ\Publish\Core\MVC\ConfigResolverInterface;
89
use Netgen\InformationCollection\API\Events;
910
use Netgen\InformationCollection\API\Value\Event\InformationCollected;
1011
use Netgen\InformationCollection\API\Value\InformationCollectionStruct;
@@ -31,11 +32,19 @@ final class Handler
3132
*/
3233
private $eventDispatcher;
3334

34-
public function __construct(FormFactoryInterface $formFactory, ContentTypeService $contentTypeService, EventDispatcherInterface $eventDispatcher)
35+
private ConfigResolverInterface $configResolver;
36+
37+
public function __construct(
38+
FormFactoryInterface $formFactory,
39+
ContentTypeService $contentTypeService,
40+
EventDispatcherInterface $eventDispatcher,
41+
ConfigResolverInterface $configResolver
42+
)
3543
{
3644
$this->formFactory = $formFactory;
3745
$this->contentTypeService = $contentTypeService;
3846
$this->eventDispatcher = $eventDispatcher;
47+
$this->configResolver = $configResolver;
3948
}
4049

4150
public function getForm(Content $content, Location $location): FormInterface
@@ -47,11 +56,31 @@ public function getForm(Content $content, Location $location): FormInterface
4756
$data = $informationCollectionMapper->mapToFormData($content, $location, $contentType);
4857

4958
return $this->formFactory->create(InformationCollectionType::class, $data, [
50-
'languageCode' => $content->contentInfo->mainLanguageCode,
59+
'languageCode' => $this->determineLanguageToLoad($content),
5160
'mainLanguageCode' => $content->contentInfo->mainLanguageCode,
5261
]);
5362
}
5463

64+
/**
65+
* @param Content $content
66+
* @return string
67+
*/
68+
private function determineLanguageToLoad(Content $content)
69+
{
70+
$versionInfo = $content->getVersionInfo();
71+
72+
$siteAccessLanguagesCodes = (array)$this->configResolver->getParameter('languages');
73+
foreach($siteAccessLanguagesCodes as $languageCode)
74+
{
75+
if (in_array($languageCode, $versionInfo->languageCodes))
76+
{
77+
return $languageCode;
78+
}
79+
}
80+
81+
return $content->contentInfo->mainLanguageCode;
82+
}
83+
5584
public function handle(InformationCollectionStruct $struct, array $options): void
5685
{
5786
$event = new InformationCollected($struct, $options);

lib/Resources/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ services:
8484
- "@form.factory"
8585
- "@ezpublish.api.service.content_type"
8686
- "@event_dispatcher"
87+
- "@ezpublish.config.resolver"
8788

8889
Netgen\InformationCollection\Core\Service\CaptchaService:
8990
autowire: true

0 commit comments

Comments
 (0)