Skip to content

Commit 6c5823e

Browse files
committed
cr remarks
1 parent df3e41d commit 6c5823e

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/lib/EventListener/UserProfileListener.php

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,10 @@ public static function getSubscribedEvents(): array
6969

7070
public function onUserUpdate(FormActionEvent $event): void
7171
{
72-
if (!$this->doesOriginateFromProfileEditing()) {
73-
return;
74-
}
75-
7672
$form = $event->getForm();
7773
$data = $event->getData();
7874

79-
if (!($data instanceof UserUpdateData) || !$this->isUserProfileUpdate($data)) {
75+
if (!($data instanceof UserUpdateData) || !$this->isSupported($data)) {
8076
return;
8177
}
8278

@@ -98,12 +94,7 @@ public function onUserUpdate(FormActionEvent $event): void
9894

9995
public function onUserCancel(FormActionEvent $event): void
10096
{
101-
if (!$this->doesOriginateFromProfileEditing()) {
102-
return;
103-
}
104-
10597
$data = $event->getData();
106-
10798
if (!($data instanceof UserUpdateData) || !$this->isSupported($data)) {
10899
return;
109100
}
@@ -112,16 +103,6 @@ public function onUserCancel(FormActionEvent $event): void
112103
$event->stopPropagation();
113104
}
114105

115-
private function doesOriginateFromProfileEditing(): bool
116-
{
117-
$request = $this->requestStack->getMainRequest();
118-
if ($request === null) {
119-
return false;
120-
}
121-
122-
return $request->attributes->get('_route') === 'ibexa.user.profile.edit';
123-
}
124-
125106
private function createRedirectToUserProfile(User $user): RedirectResponse
126107
{
127108
return new RedirectResponse(
@@ -136,7 +117,9 @@ private function createRedirectToUserProfile(User $user): RedirectResponse
136117

137118
private function isSupported(UserUpdateData $data): bool
138119
{
139-
return $this->isUserProfileUpdate($data) && $this->canEditUserProfile($data->user);
120+
return $this->isUserProfileUpdate($data) &&
121+
$this->canEditUserProfile($data->user) &&
122+
$this->doesOriginateFromProfileEditing();
140123
}
141124

142125
private function createUpdateStruct(UserUpdateData $data, string $languageCode): UserUpdateStruct
@@ -173,4 +156,14 @@ private function canEditUserProfile(User $user): bool
173156
$this->permissionResolver->canUser('user', 'selfedit', $user)
174157
&& (new IsProfileAvailable($this->configuration))->isSatisfiedBy($user);
175158
}
159+
160+
private function doesOriginateFromProfileEditing(): bool
161+
{
162+
$request = $this->requestStack->getMainRequest();
163+
if ($request === null) {
164+
return false;
165+
}
166+
167+
return $request->attributes->get('_route') === 'ibexa.user.profile.edit';
168+
}
176169
}

0 commit comments

Comments
 (0)