4
4
5
5
namespace Netgen \InformationCollection ;
6
6
7
+ use Ibexa \Contracts \Core \SiteAccess \ConfigResolverInterface ;
7
8
use Ibexa \Contracts \Core \Repository \ContentTypeService ;
8
9
use Ibexa \Contracts \Core \Repository \Values \Content \Content ;
9
10
use Ibexa \Contracts \Core \Repository \Values \Content \Location ;
@@ -24,11 +25,19 @@ final class Handler
24
25
25
26
private EventDispatcherInterface $ eventDispatcher ;
26
27
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
+ )
28
36
{
29
37
$ this ->formFactory = $ formFactory ;
30
38
$ this ->contentTypeService = $ contentTypeService ;
31
39
$ this ->eventDispatcher = $ eventDispatcher ;
40
+ $ this ->configResolver = $ configResolver ;
32
41
}
33
42
34
43
public function getForm (Content $ content , Location $ location ): FormInterface
@@ -40,11 +49,31 @@ public function getForm(Content $content, Location $location): FormInterface
40
49
$ data = $ informationCollectionMapper ->mapToFormData ($ content , $ location , $ contentType );
41
50
42
51
return $ this ->formFactory ->create (InformationCollectionType::class, $ data , [
43
- 'languageCode ' => $ content -> contentInfo -> mainLanguageCode ,
52
+ 'languageCode ' => $ this -> determineLanguageToLoad ( $ content ) ,
44
53
'mainLanguageCode ' => $ content ->contentInfo ->mainLanguageCode ,
45
54
]);
46
55
}
47
56
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
+
48
77
public function handle (InformationCollectionStruct $ struct , array $ options ): void
49
78
{
50
79
$ event = new InformationCollected ($ struct , $ options );
0 commit comments