Get errors

@param string $field (optional)
@return string[]
971383
public function errors($field = null)
    {
        if ($field) {
            return $this->errors[$field] ?? [];
        }

        return array_merge([], ...array_values($this->errors));
    }
107451
public function getInvalidRules($field = null)
    {
        return $field ?
            isset($this->invalidRules[$field]) ? $this->invalidRules[$field] : array()
            : $this->invalidRules;
    }
912750
private function getFields($field)
    {
        if ($field instanceof Group || $field instanceof Fieldset) {
            $elements = $field->getFields();
        } elseif ($field instanceof AbstractField) {
            $elements = [$field];
        } else {
            throw new \InvalidArgumentException(sprintf(
                "Invalid type '%s'",
                is_object($field) ? get_class($field) : gettype($field)
            ));
        }

        return $elements;
    }
15614
public function errors($field = null)
    {
        if ($field !== null) {
            return isset($this->_errors[$field]) ? $this->_errors[$field] : false;
        }

        return $this->_errors;
    }
6350
public function rules($field)
    {
        return (isset($this->data[$field]) && $validate = $this->data[$field]['validate']) ? $validate : array();
    }
1235419
public function hasError($field)
    {
        if (empty($this->_context['errors'])) {
            return false;
        }

        return (bool)Hash::check($this->_context['errors'], $field);
    }
1360261
private function parseField(string $field): array
    {
        $source = static::DEFAULT_SOURCE;
        $type = static::DEFAULT_TYPE;
        $origin = null;

        if (strpos($field, '(') !== false) {
            $source = substr($field, strpos($field, '(') + 1, -1);
            $field = substr($field, 0, strpos($field, '('));

            if (strpos($source, ':') !== false) {
                list($source, $origin) = explode(':', $source);
            }
        }

        if (strpos($field, ':') !== false) {
            list($field, $type) = explode(':', $field);
        }

        return [$field, $type, $source, $origin];
    }
60386
private function errorMessages(string $field, array $errors): array {
        $messages = [];

        foreach ($errors as $error) {
            $messages[] = $this->formatErrorMessage($error + ['field' => $field]);
        }
        return $messages;
    }
990140
protected function getRawErrors() {
        foreach ($this->errors as $field => $errors) {
            foreach ($errors as $error) {
                yield $field => $error;
            }
        }
    }
138952
final public function getValidationRule($field): array
    {
        $rules = $this->rules();
        $response = [];

        foreach ($rules as $rule) {
            if (Any::isArray($rule[0])) { // 2 or more rules [['field1', 'field2'], 'filter', 'filter_argv']
                foreach ($rule[0] as $tfield) {
                    if ($tfield == $field) {
                        $response[$rule[1]] = $rule[2];
                    } // ['min_length' => 1, 'required' => null]
                }
            } else { // 1 rule ['field1', 'filter', 'filter_argv']
                if ($rule[0] === $field) {
                    $response[$rule[1]] = $rule[2];
                }
            }
        }

        return $response;
    }
1335807
private function getFieldValue($field)
    {
        return isset($this->values[$field]) ? $this->values[$field] : null;
    }
71432
protected function getRulesFromField(FieldInterface $field): array
    {
        $ret = [];
        foreach ($field->getRules() as $rule) {
            $ret[] = [
                "description" => $rule->getDescription(),
                "errorMessage" => $rule->getErrorMessage(),
            ];
        }
        return $ret;
    }
256027
public function getErrors(bool $allow_multiple_errors = false) : array
    {
        if (false === $this->validated) $this->validate();
        $returned_errors = array();
        $field_names = array();

        if ($allow_multiple_errors) {
            $returned_errors = $this->validation_errors;
        } else {
            foreach ($this->validation_errors as $error) {
                if (!in_array($error->getFieldName(), $field_names)) {
                    array_push($returned_errors, $error);
                    array_push($field_names, $error->getFieldName());
                }
            }
        }
        return $returned_errors;
    }
595317
public function getErrorsByPage(): array
    {
        $result = array();
        $errors = $this->getErrors();

        foreach ($errors as $name => $val) {
            $page = $this->getFieldProperty($name, 'page');

            if ($page) {
                $result[$page][$name] = $val;
            }
        }

        return $result;
    }
1352397
public function getErrors($field = null)
	{
		return (($field) ? (array)$this->errors->$field : $this->errors->getData());
	}
507200
public function getErrors($name)
    {
        $field  = $this->getField($name);
        $errors = (null !== $field) ? $field->getErrors() : [];
        return $errors;
    }
839551
private function formatErrorList(string $field, array $errors) {
        if (empty($field)) {
            $fieldName = '';
            $colon = '%s%s';
            $sep = "\n";
        } else {
            $fieldName = $this->formatFieldName($field);
            $colon = $this->translate('%s: %s');
            $sep = "\n  ";
            if (count($errors) > 1) {
                $colon = rtrim(sprintf($colon, '%s', "")).$sep.'%s';
            }
        }

        $messages = $this->errorMessages($field, $errors);
        $result = sprintf($colon, $fieldName, implode($sep, $messages));
        return $result;
    }