5
5
use eZ \Publish \API \Repository \ContentTypeService ;
6
6
use eZ \Publish \API \Repository \Values \Content \Content ;
7
7
use eZ \Publish \API \Repository \Values \Content \Location ;
8
+ use eZ \Publish \Core \MVC \ConfigResolverInterface ;
8
9
use Netgen \InformationCollection \API \Events ;
9
10
use Netgen \InformationCollection \API \Value \Event \InformationCollected ;
10
11
use Netgen \InformationCollection \API \Value \InformationCollectionStruct ;
@@ -31,11 +32,19 @@ final class Handler
31
32
*/
32
33
private $ eventDispatcher ;
33
34
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
+ )
35
43
{
36
44
$ this ->formFactory = $ formFactory ;
37
45
$ this ->contentTypeService = $ contentTypeService ;
38
46
$ this ->eventDispatcher = $ eventDispatcher ;
47
+ $ this ->configResolver = $ configResolver ;
39
48
}
40
49
41
50
public function getForm (Content $ content , Location $ location ): FormInterface
@@ -47,11 +56,31 @@ public function getForm(Content $content, Location $location): FormInterface
47
56
$ data = $ informationCollectionMapper ->mapToFormData ($ content , $ location , $ contentType );
48
57
49
58
return $ this ->formFactory ->create (InformationCollectionType::class, $ data , [
50
- 'languageCode ' => $ content -> contentInfo -> mainLanguageCode ,
59
+ 'languageCode ' => $ this -> determineLanguageToLoad ( $ content ) ,
51
60
'mainLanguageCode ' => $ content ->contentInfo ->mainLanguageCode ,
52
61
]);
53
62
}
54
63
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
+
55
84
public function handle (InformationCollectionStruct $ struct , array $ options ): void
56
85
{
57
86
$ event = new InformationCollected ($ struct , $ options );
0 commit comments