Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-6724: Simplify context menu #68

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/bundle/Controller/UserSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
use Ibexa\User\Form\Data\UserSettingUpdateData;
use Ibexa\User\Form\Factory\FormFactory;
use Ibexa\User\Form\SubmitHandler;
use Ibexa\User\Form\Type\UserSettingUpdateType;
use Ibexa\User\UserSetting\UserSettingService;
use Ibexa\User\UserSetting\ValueDefinitionRegistry;
use Ibexa\User\View\UserSettings\ListView;
use Ibexa\User\View\UserSettings\UpdateView;
use JMS\TranslationBundle\Annotation\Desc;
use Symfony\Component\Form\Button;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -90,7 +92,7 @@ public function updateAction(Request $request, UpdateView $view)
$form->handleRequest($request);

if ($form->isSubmitted()) {
$result = $this->submitHandler->handle($form, function (UserSettingUpdateData $data) {
$result = $this->submitHandler->handle($form, function (UserSettingUpdateData $data) use ($form) {
konradoboza marked this conversation as resolved.
Show resolved Hide resolved
foreach ($data->getValues() as $identifier => $value) {
$this->userSettingService->setUserSetting($identifier, (string)$value['value']);
}
Expand All @@ -102,6 +104,14 @@ public function updateAction(Request $request, UpdateView $view)
'ibexa_user_settings'
);

if ($form->getClickedButton() instanceof Button
&& $form->getClickedButton()->getName() === UserSettingUpdateType::BTN_UPDATE_AND_EDIT
Comment on lines +107 to +108
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: it's usually more optimal to extract $form->getClickedButton() instead of calling it twice, unless it's a property getter.

) {
return $this->redirectToRoute('ibexa.user_settings.update', [
'identifier' => $data->getIdentifier(),
]);
}

return new RedirectResponse($this->generateUrl('ibexa.user_settings.list'));
});

Expand Down
3 changes: 3 additions & 0 deletions src/lib/Form/Type/UserSettingUpdateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

class UserSettingUpdateType extends AbstractType
{
public const BTN_UPDATE_AND_EDIT = 'update_and_edit';

/** @var \Ibexa\User\UserSetting\FormMapperRegistry */
protected $formMapperRegistry;

Expand Down Expand Up @@ -68,6 +70,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->add($sub);
}
$builder->add('update', SubmitType::class, []);
$builder->add(self::BTN_UPDATE_AND_EDIT, SubmitType::class);
}

/**
Expand Down
Loading