fix: [crud] fixed the broken non ajax messages just introduced in the previous commit

- can't have my cake and eat it too
pull/187/head
iglocska 2024-11-22 12:47:16 +01:00
parent ac33e90f0c
commit ab331dcfb9
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 8 additions and 6 deletions

View File

@ -472,7 +472,7 @@ class CRUDComponent extends Component
} catch (\Exception $e) { } catch (\Exception $e) {
$message = $e->getMessage(); $message = $e->getMessage();
$break = true; $break = true;
$this->__raiseErrorToUser(__('Could not save {0}.', $this->ObjectAlias), ['Custom checks' => ['Custom checks' => $message]]); $this->__raiseErrorToUser(__('Could not save {0}.', $this->ObjectAlias), $message);
} }
if ($data === false) { if ($data === false) {
$break = true; $break = true;
@ -488,7 +488,7 @@ class CRUDComponent extends Component
} catch (\Exception $e) { } catch (\Exception $e) {
$message = $e->getMessage(); $message = $e->getMessage();
$break = true; $break = true;
$this->__raiseErrorToUser(__('Saved {0}, but could not execute post-save actions.', $this->ObjectAlias), ['Custom checks' => ['Custom checks' => $message]]); $this->__raiseErrorToUser(__('Saved {0}, but could not execute post-save actions.', $this->ObjectAlias), $message);
} }
if ($data === false) { if ($data === false) {
$break = true; $break = true;
@ -748,10 +748,12 @@ class CRUDComponent extends Component
private function __raiseErrorToUser($title, $message = null) private function __raiseErrorToUser($title, $message = null)
{ {
if ($this->Controller->ParamHandler->isRest()) { if ($this->Controller->ParamHandler->isRest()) {
$this->Controller->restResponsePayload = $this->RestResponse->viewData($message, 'json');
} else if ($this->Controller->ParamHandler->isAjax()) { } else if ($this->Controller->ParamHandler->isAjax()) {
$this->Controller->ajaxResponsePayload = $this->RestResponse->ajaxFailResponse($this->ObjectAlias, 'edit', [], $title, $message); $this->Controller->ajaxResponsePayload = $this->RestResponse->ajaxFailResponse($this->ObjectAlias, 'edit', [], $title, ['Custom checks' => ['Custom checks' => $message]]);
} else { } else {
throw new NotFoundException($message); $this->Controller->isFailResponse = true;
$this->Controller->Flash->error($message);
} }
} }
@ -839,7 +841,7 @@ class CRUDComponent extends Component
} catch (\Exception $e) { } catch (\Exception $e) {
$message = $e->getMessage(); $message = $e->getMessage();
$break = true; $break = true;
$this->__raiseErrorToUser(__('Could not save {0}.', $this->ObjectAlias), ['Custom checks' => ['Custom checks' => $message]]); $this->__raiseErrorToUser(__('Could not save {0}.', $this->ObjectAlias), $message);
} }
if ($data === false) { if ($data === false) {
$break = true; $break = true;
@ -867,7 +869,7 @@ class CRUDComponent extends Component
} catch (\Exception $e) { } catch (\Exception $e) {
$message = $e->getMessage(); $message = $e->getMessage();
$break = true; $break = true;
$this->__raiseErrorToUser(__('Saved {0} `{1}`, but could not execute post-save actions.', $this->ObjectAlias, $savedData->{$this->Table->getDisplayField()}), ['Custom checks' => ['Custom checks' => $message]]); $this->__raiseErrorToUser(__('Saved {0} `{1}`, but could not execute post-save actions.', $this->ObjectAlias, $savedData->{$this->Table->getDisplayField()}), $message);
} }
if ($data === false) { if ($data === false) {
$break = true; $break = true;