55use eZ \Publish \API \Repository \ContentTypeService ;
66use eZ \Publish \API \Repository \Values \Content \Content ;
77use eZ \Publish \API \Repository \Values \Content \Location ;
8+ use eZ \Publish \Core \MVC \ConfigResolverInterface ;
89use Netgen \InformationCollection \API \Events ;
910use Netgen \InformationCollection \API \Value \Event \InformationCollected ;
1011use 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 );
0 commit comments