44
55namespace Netgen \InformationCollection ;
66
7+ use Ibexa \Contracts \Core \SiteAccess \ConfigResolverInterface ;
78use Ibexa \Contracts \Core \Repository \ContentTypeService ;
89use Ibexa \Contracts \Core \Repository \Values \Content \Content ;
910use Ibexa \Contracts \Core \Repository \Values \Content \Location ;
@@ -24,11 +25,19 @@ final class Handler
2425
2526 private EventDispatcherInterface $ eventDispatcher ;
2627
27- public function __construct (FormFactoryInterface $ formFactory , ContentTypeService $ contentTypeService , EventDispatcherInterface $ eventDispatcher )
28+ private ConfigResolverInterface $ configResolver ;
29+
30+ public function __construct (
31+ FormFactoryInterface $ formFactory ,
32+ ContentTypeService $ contentTypeService ,
33+ EventDispatcherInterface $ eventDispatcher ,
34+ ConfigResolverInterface $ configResolver
35+ )
2836 {
2937 $ this ->formFactory = $ formFactory ;
3038 $ this ->contentTypeService = $ contentTypeService ;
3139 $ this ->eventDispatcher = $ eventDispatcher ;
40+ $ this ->configResolver = $ configResolver ;
3241 }
3342
3443 public function getForm (Content $ content , Location $ location ): FormInterface
@@ -40,11 +49,31 @@ public function getForm(Content $content, Location $location): FormInterface
4049 $ data = $ informationCollectionMapper ->mapToFormData ($ content , $ location , $ contentType );
4150
4251 return $ this ->formFactory ->create (InformationCollectionType::class, $ data , [
43- 'languageCode ' => $ content -> contentInfo -> mainLanguageCode ,
52+ 'languageCode ' => $ this -> determineLanguageToLoad ( $ content ) ,
4453 'mainLanguageCode ' => $ content ->contentInfo ->mainLanguageCode ,
4554 ]);
4655 }
4756
57+ /**
58+ * @param Content $content
59+ * @return string
60+ */
61+ private function determineLanguageToLoad (Content $ content ): string
62+ {
63+ $ versionInfo = $ content ->getVersionInfo ();
64+
65+ $ siteAccessLanguagesCodes = (array )$ this ->configResolver ->getParameter ('languages ' );
66+ foreach ($ siteAccessLanguagesCodes as $ languageCode )
67+ {
68+ if (in_array ($ languageCode , $ versionInfo ->languageCodes , true ))
69+ {
70+ return $ languageCode ;
71+ }
72+ }
73+
74+ return $ content ->contentInfo ->mainLanguageCode ;
75+ }
76+
4877 public function handle (InformationCollectionStruct $ struct , array $ options ): void
4978 {
5079 $ event = new InformationCollected ($ struct , $ options );
0 commit comments