From c2638e91934ac9ce119005a43b138e23e48d3a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 2 Jun 2023 23:54:44 +0200 Subject: [PATCH 1/2] check for Form::HOOK_SUBMIT hooks is not needed --- src/UserAction/StepExecutorTrait.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/UserAction/StepExecutorTrait.php b/src/UserAction/StepExecutorTrait.php index 3909d83f51..8fbd584999 100644 --- a/src/UserAction/StepExecutorTrait.php +++ b/src/UserAction/StepExecutorTrait.php @@ -177,14 +177,12 @@ protected function doFields(View $page): void $this->jsSetSubmitButton($page, $form, $this->step); $this->jsSetPreviousHandler($page, $this->step); - if (!$form->hookHasCallbacks(Form::HOOK_SUBMIT)) { - $form->onSubmit(function (Form $form) { - // collect fields defined in Model\UserAction - $this->setActionDataFromModel('fields', $form->model, $this->action->fields); + $form->onSubmit(function (Form $form) { + // collect fields defined in Model\UserAction + $this->setActionDataFromModel('fields', $form->model, $this->action->fields); - return $this->jsStepSubmit($this->step); - }); - } + return $this->jsStepSubmit($this->step); + }); } protected function doPreview(View $page): void From de259e0ccb2472af4a753a47daced42aa14f89f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 3 Jun 2023 00:08:50 +0200 Subject: [PATCH 2/2] Remove StepExecutorTrait::jsStepSubmit exception handling --- src/UserAction/StepExecutorTrait.php | 55 ++++++++++------------------ 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/src/UserAction/StepExecutorTrait.php b/src/UserAction/StepExecutorTrait.php index 8fbd584999..7006b2007f 100644 --- a/src/UserAction/StepExecutorTrait.php +++ b/src/UserAction/StepExecutorTrait.php @@ -7,14 +7,12 @@ use Atk4\Core\Factory; use Atk4\Data\Model; use Atk4\Data\Model\UserAction; -use Atk4\Data\ValidationException; use Atk4\Ui\Button; use Atk4\Ui\Form; use Atk4\Ui\Js\JsBlock; use Atk4\Ui\Js\JsExpressionable; use Atk4\Ui\Js\JsFunction; use Atk4\Ui\Loader; -use Atk4\Ui\Message; use Atk4\Ui\View; trait StepExecutorTrait @@ -405,42 +403,29 @@ protected function jsSetSubmitButton(View $view, Form $form, string $step): void /** * Get proper JS after submitting a form in a step. - * - * @return JsBlock|View */ - protected function jsStepSubmit(string $step) + protected function jsStepSubmit(string $step): JsBlock { - try { - if (count($this->steps) === 1) { - // collect argument and execute action - $return = $this->action->execute(...$this->getActionArgs($this->getActionData('args'))); - $js = $this->jsGetExecute($return, $this->action->getEntity()->getId()); - } else { - // store data and setup reload - $js = new JsBlock([ - $this->loader->jsAddStoreData($this->actionData, true), - $this->loader->jsLoad( - [ - 'step' => $this->isLastStep($step) ? 'final' : $this->getNextStep($step), - $this->name => $this->action->getEntity()->getId(), - ], - ['method' => 'POST'], - $this->loader->name - ), - ]); - } - - return $js; - } catch (ValidationException $e) { - throw $e; // handled by Form::onSubmit() method - } catch (\Throwable $e) { - $msg = new Message(['Error executing ' . $this->action->caption, 'type' => 'error', 'class.red' => true]); - $msg->setApp($this->getApp()); - $msg->invokeInit(); - $msg->text->content = $this->getApp()->renderExceptionHtml($e); - - return $msg; + if (count($this->steps) === 1) { + // collect argument and execute action + $return = $this->action->execute(...$this->getActionArgs($this->getActionData('args'))); + $js = $this->jsGetExecute($return, $this->action->getEntity()->getId()); + } else { + // store data and setup reload + $js = new JsBlock([ + $this->loader->jsAddStoreData($this->actionData, true), + $this->loader->jsLoad( + [ + 'step' => $this->isLastStep($step) ? 'final' : $this->getNextStep($step), + $this->name => $this->action->getEntity()->getId(), + ], + ['method' => 'POST'], + $this->loader->name + ), + ]); } + + return $js; } protected function getActionData(string $step): array