Skip to content

Commit

Permalink
Form: Register form notifications as custom error messages for API re…
Browse files Browse the repository at this point in the history
…quests

I'd have liked to fix how we transmit validation messages in such cases,
but for compatibilty reasons this has to suffice..
  • Loading branch information
nilmerg committed Jul 13, 2017
1 parent 96c96df commit ed5ba14
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions library/Icinga/Web/Form.php
Expand Up @@ -1580,7 +1580,12 @@ public function assertPermission($permission)
*/
public function error($message, $markAsError = true)
{
$this->addNotification($message, self::NOTIFICATION_ERROR);
if ($this->getIsApiTarget()) {
$this->addErrorMessage($message);
} else {
$this->addNotification($message, self::NOTIFICATION_ERROR);
}

if ($markAsError) {
$this->markAsError();
}
Expand All @@ -1598,7 +1603,12 @@ public function error($message, $markAsError = true)
*/
public function warning($message, $markAsError = true)
{
$this->addNotification($message, self::NOTIFICATION_WARNING);
if ($this->getIsApiTarget()) {
$this->addErrorMessage($message);
} else {
$this->addNotification($message, self::NOTIFICATION_WARNING);
}

if ($markAsError) {
$this->markAsError();
}
Expand All @@ -1616,7 +1626,12 @@ public function warning($message, $markAsError = true)
*/
public function info($message, $markAsError = true)
{
$this->addNotification($message, self::NOTIFICATION_INFO);
if ($this->getIsApiTarget()) {
$this->addErrorMessage($message);
} else {
$this->addNotification($message, self::NOTIFICATION_INFO);
}

if ($markAsError) {
$this->markAsError();
}
Expand Down

0 comments on commit ed5ba14

Please sign in to comment.