1717use Ibexa \Contracts \Core \Repository \Values \ContentType \ContentType ;
1818use Ibexa \Core \Base \Exceptions \InvalidArgumentException ;
1919use Ibexa \Core \MVC \Symfony \View \Builder \ViewBuilder ;
20+ use Ibexa \Core \MVC \Symfony \View \ContentView ;
21+ use Ibexa \Core \MVC \Symfony \View \View ;
2022use Symfony \Component \Form \FormError ;
2123
2224/**
2325 * Builds ContentEditView objects.
2426 *
2527 * @internal
2628 */
27- class ContentEditViewBuilder extends AbstractContentViewBuilder implements ViewBuilder
29+ final class ContentEditViewBuilder extends AbstractContentViewBuilder implements ViewBuilder
2830{
29- public function matches ($ argument )
31+ public function matches (mixed $ argument ): bool
3032 {
3133 return 'ibexa_content_edit::editVersionDraftAction ' === $ argument ;
3234 }
3335
3436 /**
35- * @param array $parameters
37+ * @param array<string, mixed> $parameters
3638 *
37- * @return \Ibexa\Core\MVC\Symfony\View\ContentView|\Ibexa\Core\MVC\Symfony\View\View
38- *
39- * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
4039 * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
4140 * @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
4241 * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
4342 * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
4443 */
45- public function buildView (array $ parameters )
44+ public function buildView (array $ parameters ): ContentView | View
4645 {
47- $ view = new ContentEditView ($ this ->configResolver ->getParameter ('content_edit.templates.edit ' ));
46+ $ view = new ContentEditView (
47+ $ this ->configResolver ->getParameter ('content_edit.templates.edit ' )
48+ );
4849
4950 $ language = $ this ->resolveLanguage ($ parameters );
5051 $ location = $ this ->resolveLocation ($ parameters );
5152 $ content = $ this ->resolveContent ($ parameters , $ location , $ language );
52- $ contentInfo = $ content ->contentInfo ;
53- $ contentType = $ this ->loadContentType ((int ) $ contentInfo ->contentTypeId , $ this ->languagePreferenceProvider ->getPreferredLanguages ());
53+ $ contentInfo = $ content ->getContentInfo ();
54+ $ contentType = $ this ->loadContentType (
55+ $ contentInfo ->contentTypeId ,
56+ $ this ->languagePreferenceProvider ->getPreferredLanguages ()
57+ );
58+
5459 /** @var \Symfony\Component\Form\Form $form */
5560 $ form = $ parameters ['form ' ];
56- $ isPublished = null !== $ contentInfo ->mainLocationId && $ contentInfo ->published ;
61+ $ isPublished = null !== $ contentInfo ->getMainLocationId () && $ contentInfo ->isPublished () ;
5762
5863 if (!$ content ->getVersionInfo ()->isDraft ()) {
5964 throw new InvalidArgumentException ('Version ' , 'The status is not draft ' );
@@ -62,16 +67,22 @@ public function buildView(array $parameters)
6267 if (null === $ location && $ isPublished ) {
6368 try {
6469 // assume main location if no location was provided
65- $ location = $ this ->loadLocation ((int )$ contentInfo ->mainLocationId );
66- } catch (UnauthorizedException $ e ) {
70+ $ location = $ this ->loadLocation ((int )$ contentInfo ->getMainLocationId () );
71+ } catch (UnauthorizedException ) {
6772 // if no access to the main location assume content has multiple locations and first of them can be used
68- $ availableLocations = $ this ->repository ->getLocationService ()->loadLocations ($ contentInfo );
73+ $ availableLocations = iterator_to_array (
74+ $ this ->repository ->getLocationService ()->loadLocations ($ contentInfo )
75+ );
76+
6977 $ location = array_shift ($ availableLocations );
7078 }
7179 }
7280
73- if (null !== $ location && $ location ->contentId !== $ content ->id ) {
74- throw new InvalidArgumentException ('Location ' , 'The provided Location does not belong to the selected content ' );
81+ if (null !== $ location && $ location ->getContentId () !== $ content ->getId ()) {
82+ throw new InvalidArgumentException (
83+ 'Location ' ,
84+ 'The provided Location does not belong to the selected content '
85+ );
7586 }
7687
7788 if ($ form ->isSubmitted () && $ form ->isValid () && null !== $ form ->getClickedButton ()) {
@@ -100,7 +111,7 @@ public function buildView(array $parameters)
100111
101112 foreach ($ validationErrors as $ fieldIdentifier => $ validationErrorLanguages ) {
102113 $ fieldValueElement = $ form ->get ('fieldsData ' )->get ($ fieldIdentifier )->get ('value ' );
103- foreach ($ validationErrorLanguages as $ languageCode => $ validationErrors ) {
114+ foreach ($ validationErrorLanguages as $ validationErrors ) {
104115 if (is_array ($ validationErrors ) === false ) {
105116 $ validationErrors = [$ validationErrors ];
106117 }
@@ -138,28 +149,21 @@ public function buildView(array $parameters)
138149 /**
139150 * Loads Content with id $contentId.
140151 *
141- * @param int $contentId
142- * @param array $languages
143- * @param int|null $versionNo
144- *
145- * @return \Ibexa\Contracts\Core\Repository\Values\Content\Content
152+ * @param string[] $languages
146153 *
147154 * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
148155 * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
149156 */
150- private function loadContent (int $ contentId , array $ languages = [], int $ versionNo = null ): Content
157+ private function loadContent (int $ contentId , array $ languages = [], ? int $ versionNo = null ): Content
151158 {
152159 return $ this ->repository ->getContentService ()->loadContent ($ contentId , $ languages , $ versionNo );
153160 }
154161
155162 /**
156163 * Loads ContentType with id $contentTypeId.
157164 *
158- * @param int $contentTypeId
159165 * @param string[] $languageCodes
160166 *
161- * @return \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType
162- *
163167 * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
164168 */
165169 private function loadContentType (int $ contentTypeId , array $ languageCodes ): ContentType
@@ -168,13 +172,11 @@ private function loadContentType(int $contentTypeId, array $languageCodes): Cont
168172 }
169173
170174 /**
171- * @param array $parameters
172- * @param \Ibexa\Contracts\Core\Repository\Values\Content\Location|null $location
173- * @param \Ibexa\Contracts\Core\Repository\Values\Content\Language $language
175+ * @param array<string, mixed> $parameters
174176 *
175- * @return \Ibexa\Contracts\ Core\Repository\Values\Content\Content
176- *
177- * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
177+ * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException
178+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
179+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
178180 */
179181 private function resolveContent (array $ parameters , ?Location $ location , Language $ language ): Content
180182 {
@@ -185,7 +187,7 @@ private function resolveContent(array $parameters, ?Location $location, Language
185187 if (isset ($ parameters ['contentId ' ])) {
186188 $ contentId = $ parameters ['contentId ' ];
187189 } elseif (null !== $ location ) {
188- $ contentId = $ location ->contentId ;
190+ $ contentId = $ location ->getContentId () ;
189191 } else {
190192 throw new InvalidArgumentException (
191193 'Content ' ,
@@ -195,15 +197,13 @@ private function resolveContent(array $parameters, ?Location $location, Language
195197
196198 return $ this ->loadContent (
197199 (int ) $ contentId ,
198- null !== $ language ? [$ language ->languageCode ] : [ ],
199- (int ) $ parameters ['versionNo ' ] ?: null
200+ [$ language ->languageCode ],
201+ (int )$ parameters ['versionNo ' ] ?: null
200202 );
201203 }
202204
203205 /**
204- * @param array $parameters
205- *
206- * @return \Ibexa\Contracts\Core\Repository\Values\Content\Location|null
206+ * @param array<string, mixed> $parameters
207207 */
208208 private function resolveLocation (array $ parameters ): ?Location
209209 {
@@ -212,7 +212,8 @@ private function resolveLocation(array $parameters): ?Location
212212 // the load error is suppressed because a user can have no permission to this location
213213 // but can have access to another location when content is in multiple locations
214214 return $ this ->loadLocation ((int )$ parameters ['locationId ' ]);
215- } catch (UnauthorizedException $ e ) {
215+ } catch (UnauthorizedException ) {
216+ //do nothing
216217 }
217218 }
218219
0 commit comments