Skip to content

Commit 28c8666

Browse files
committed
fixed issues with dispatching form events
1 parent f45162c commit 28c8666

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+242
-681
lines changed

dependencies.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

phpstan-baseline.neon

Lines changed: 3 additions & 351 deletions
Large diffs are not rendered by default.

src/bundle/Resources/config/views.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ services:
3636
$parameterName: content_edit_view
3737

3838
Ibexa\ContentForms\Content\View\Filter\ContentEditViewFilter:
39-
arguments:
40-
- '@ibexa.api.service.content'
41-
- '@ibexa.api.service.location'
42-
- '@ibexa.api.service.content_type'
4339
tags:
4440
- { name: kernel.event_subscriber }
4541

src/contracts/Content/Form/Provider/GroupedContentFormFieldsProviderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
interface GroupedContentFormFieldsProviderInterface
1212
{
1313
/**
14-
* @param \Symfony\Component\Form\FormInterface[] $fieldsDataForm
14+
* @param \Symfony\Component\Form\FormInterface<mixed>[] $fieldsDataForm
1515
*
1616
* @phpstan-return array<string, array<int, string>> Array of fieldGroupIdentifier grouped by fieldGroupName.
1717
*/

src/lib/Content/View/Builder/AbstractContentViewBuilder.php

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,16 @@
2525
*/
2626
abstract class AbstractContentViewBuilder
2727
{
28-
protected Repository $repository;
29-
30-
protected Configurator $viewConfigurator;
31-
32-
protected ParametersInjector $viewParametersInjector;
33-
34-
protected ActionDispatcherInterface $contentActionDispatcher;
35-
36-
protected UserLanguagePreferenceProviderInterface $languagePreferenceProvider;
37-
38-
protected ConfigResolverInterface $configResolver;
39-
40-
protected GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider;
41-
42-
protected ContentService $contentService;
43-
4428
public function __construct(
45-
Repository $repository,
46-
Configurator $viewConfigurator,
47-
ParametersInjector $viewParametersInjector,
48-
ActionDispatcherInterface $contentActionDispatcher,
49-
UserLanguagePreferenceProviderInterface $languagePreferenceProvider,
50-
ConfigResolverInterface $configResolver,
51-
GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider,
52-
ContentService $contentService
29+
protected Repository $repository,
30+
protected Configurator $viewConfigurator,
31+
protected ParametersInjector $viewParametersInjector,
32+
protected ActionDispatcherInterface $contentActionDispatcher,
33+
protected UserLanguagePreferenceProviderInterface $languagePreferenceProvider,
34+
protected ConfigResolverInterface $configResolver,
35+
protected GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider,
36+
protected ContentService $contentService
5337
) {
54-
$this->repository = $repository;
55-
$this->viewConfigurator = $viewConfigurator;
56-
$this->viewParametersInjector = $viewParametersInjector;
57-
$this->contentActionDispatcher = $contentActionDispatcher;
58-
$this->languagePreferenceProvider = $languagePreferenceProvider;
59-
$this->configResolver = $configResolver;
60-
$this->groupedContentFormFieldsProvider = $groupedContentFormFieldsProvider;
61-
$this->contentService = $contentService;
6238
}
6339

6440
/**
@@ -81,6 +57,8 @@ private function loadLanguage(string $languageCode): Language
8157
}
8258

8359
/**
60+
* @param array<string, mixed> $parameters
61+
*
8462
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
8563
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
8664
*/

src/lib/Content/View/Builder/ContentCreateViewBuilder.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,21 @@
2020
*
2121
* @internal
2222
*/
23-
class ContentCreateViewBuilder extends AbstractContentViewBuilder implements ViewBuilder
23+
final class ContentCreateViewBuilder extends AbstractContentViewBuilder implements ViewBuilder
2424
{
25-
public function matches($argument)
25+
public function matches($argument): bool
2626
{
2727
return 'ibexa_content_edit::createWithoutDraftAction' === $argument;
2828
}
2929

3030
/**
31-
* @param array $parameters
32-
*
33-
* @return \Ibexa\ContentForms\Content\View\ContentCreateSuccessView|\Ibexa\ContentForms\Content\View\ContentCreateView
31+
* @param array<string, mixed> $parameters
3432
*
3533
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
3634
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
3735
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
3836
*/
39-
public function buildView(array $parameters)
37+
public function buildView(array $parameters): ContentCreateSuccessView|ContentCreateView
4038
{
4139
$view = new ContentCreateView($this->configResolver->getParameter('content_edit.templates.create'));
4240

@@ -86,11 +84,8 @@ public function buildView(array $parameters)
8684
/**
8785
* Loads ContentType with identifier $contentTypeIdentifier.
8886
*
89-
* @param string $contentTypeIdentifier
9087
* @param string[] $prioritizedLanguages
9188
*
92-
* @return \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType
93-
*
9489
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
9590
*/
9691
private function loadContentType(string $contentTypeIdentifier, array $prioritizedLanguages = []): ContentType
@@ -102,10 +97,8 @@ private function loadContentType(string $contentTypeIdentifier, array $prioritiz
10297
}
10398

10499
/**
105-
* @param array $parameters
106-
* @param array $languageCodes
107-
*
108-
* @return \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType
100+
* @param array<string, mixed> $parameters
101+
* @param string[] $languageCodes
109102
*
110103
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
111104
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
@@ -127,9 +120,7 @@ private function resolveContentType(array $parameters, array $languageCodes): Co
127120
}
128121

129122
/**
130-
* @param array $parameters
131-
*
132-
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Location
123+
* @param array<string, mixed> $parameters
133124
*
134125
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
135126
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException

src/lib/Content/View/Builder/ContentEditViewBuilder.php

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,48 @@
1717
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
1818
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
1919
use Ibexa\Core\MVC\Symfony\View\Builder\ViewBuilder;
20+
use Ibexa\Core\MVC\Symfony\View\ContentView;
21+
use Ibexa\Core\MVC\Symfony\View\View;
2022
use 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

src/lib/Content/View/ContentCreateDraftView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
use Ibexa\Core\MVC\Symfony\View\BaseView;
1212
use Ibexa\Core\MVC\Symfony\View\View;
1313

14-
class ContentCreateDraftView extends BaseView implements View
14+
final class ContentCreateDraftView extends BaseView implements View
1515
{
1616
}

src/lib/Content/View/ContentCreateSuccessView.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
use Symfony\Component\HttpFoundation\Response;
1515
use Symfony\Component\HttpKernel\Controller\ControllerReference;
1616

17-
class ContentCreateSuccessView extends BaseView implements LocationValueView
17+
final class ContentCreateSuccessView extends BaseView implements LocationValueView
1818
{
1919
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location|null */
2020
private ?Location $location = null;
2121

2222
/**
23-
* @param \Symfony\Component\HttpFoundation\Response $response
24-
*
2523
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
2624
*/
2725
public function __construct(Response $response)
@@ -32,17 +30,11 @@ public function __construct(Response $response)
3230
$this->setControllerReference(new ControllerReference('ibexa_content_edit::createWithoutDraftSuccessAction'));
3331
}
3432

35-
/**
36-
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Location|null $location
37-
*/
3833
public function setLocation(?Location $location): void
3934
{
4035
$this->location = $location;
4136
}
4237

43-
/**
44-
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Location|null
45-
*/
4638
public function getLocation(): ?Location
4739
{
4840
return $this->location;

0 commit comments

Comments
 (0)