public static errorMessage ( array $error ) : string | ||
$error | array | The error array. |
return | string | Returns the message from the error. |
public static function errorMessage(array $error)
{
if (isset($error['message'])) {
return $error['message'];
} else {
$field = val('field', $error, '*');
if (is_array($field)) {
$field = implode(', ', $field);
}
return sprintft($error['code'] . ': %s.', $field);
}
}
/** * Specify data which should be serialized to JSON. * * @link http://php.net/manual/en/jsonserializable.jsonserialize.php * @return mixed data which can be serialized by <b>json_encode</b>, * which is a value of any type other than a resource. */ public function jsonSerialize() { $errors = $this->validation->getErrorsFlat(); if (count($errors) === 1) { $message = Validation::errorMessage($errors[0]); } else { $message = t('Validation failed.'); } $result = ['message' => $message, 'status' => $this->getCode(), 'errors' => $errors]; return $result; }