Garden\Validation::errorMessage PHP Method

errorMessage() public static method

Errors are stored with either a message or a translation code. This method will look at both to determine the full message.
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);
        }
    }

Usage Example

 /**
  * 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;
 }