/** * Formatting the property_path * * @param FormError $error The form error * * @return string|null */ private function formatPropertyPath(FormError $error) { $path = $error->getCause()->getPropertyPath(); if (empty($path)) { return; } $path = preg_replace('/^(data.)|(.data)|(\\])|(\\[)|children/', '', $path); return $path; }
/** * @param FormError $error * @param FormInterface|null $form * @return ErrorField */ protected function toErrorArray(FormError $error, FormInterface $form = null) { if (is_null($form)) { $field = self::FIELD_ROOT; } else { $field = $form->getName(); } if (!is_null($error->getCause()) && !is_null($error->getCause()->getConstraint())) { $code = $this->getErrorCode(StringUtil::classToSnakeCase($error->getCause()->getConstraint())); } else { $code = $this->getErrorCodeByMessage($error); } return new ErrorField($field, $code, $error->getMessage()); }
/** * @param FormError $error * @param FormInterface|null $form * @return array */ protected function toErrorArray(FormError $error, FormInterface $form = null) { $data = []; if (is_null($form)) { $data['field'] = '#'; } else { $data['field'] = $form->getName(); } if (!is_null($error->getCause()) && !is_null($error->getCause()->getConstraint())) { $data['code'] = $this->getErrorCode(StringUtil::classToSnakeCase($error->getCause()->getConstraint())); } else { $this->getErrorCodeByMessage($error); } $data['message'] = $error->getMessage(); return $data; }