本文整理汇总了PHP中Symfony\Component\Form\Form::isRoot方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::isRoot方法的具体用法?PHP Form::isRoot怎么用?PHP Form::isRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\Form
的用法示例。
在下文中一共展示了Form::isRoot方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFormErrorMessages
private function getFormErrorMessages(Form $form)
{
$errors = [];
foreach ($form->getErrors() as $key => $error) {
if ($form->isRoot()) {
$errors['#root'][] = $error->getMessage();
} else {
$errors[] = $error->getMessage();
}
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getFormErrorMessages($child);
}
}
return $errors;
}
示例2: getErrorMessages
private function getErrorMessages(\Symfony\Component\Form\Form $form)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
if ($form->isRoot()) {
$errors['#'][] = $error->getMessage();
} else {
$errors[] = $error->getMessage();
}
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getErrorMessages($child);
}
}
return $errors;
}
示例3: getErrorMessages
/**
* This method comes from Flip's answer on Stackoverflow:
* http://stackoverflow.com/a/17428869/731138
*
* @param Form $form
* @return array
*/
protected function getErrorMessages(Form $form)
{
$errors = array();
foreach ($form->getErrors() as $error) {
if ($form->isRoot()) {
$errors['#'][] = $error->getMessage();
} else {
$errors[] = $error->getMessage();
}
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getErrorMessages($child);
}
}
return $errors;
}
示例4: getErrorMessages
/**
* @param Form $form
* @return array
*/
protected function getErrorMessages(Form $form)
{
$errors = [];
foreach ($form->getErrors() as $key => $error) {
if ($form->isRoot()) {
$errors[] = $this->toErrorArray($error);
} else {
$errors[] = $this->toErrorArray($error, $form);
}
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
foreach ($this->getErrorMessages($child) as $error) {
$errors[] = $error;
}
}
}
return $errors;
}
示例5: getFormErrorMessagesWithLabels
public function getFormErrorMessagesWithLabels(Form $form, FormHelper $formHelper)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
if ($form->isRoot()) {
$errors['#'][] = $error->getMessage();
} else {
$errors[] = $error->getMessage();
}
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$label = $child->getConfig()->getOption('label');
if (!$label) {
$label = $formHelper->humanize($child->getName());
}
$errors[$label] = $this->getFormErrorMessagesWithLabels($child, $formHelper);
}
}
return $errors;
}
示例6: getErrorMessages
public static function getErrorMessages(\Symfony\Component\Form\Form $form)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
if ($form->isRoot()) {
$errors['#'][] = $error->getMessage();
} else {
$errors[] = $error->getMessage();
}
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$err = self::getErrorMessages($child);
if (!empty($err)) {
$errors[$child->getName()] = $err;
}
}
}
$checkError = current($errors);
if (!empty($checkError)) {
return $errors;
} else {
return;
}
}
示例7: getFormErrors
/**
* Dado un formulario se devuelven sus errores parseados
* @param Form $form
* @param bool $deep option for Form getErrors method
* @param bool $flatten option for Form getErrors method
* @return array
*/
public function getFormErrors(Form $form, $deep = false, $flatten = true)
{
// Se parsean los errores que existan en el formulario para devolverlos en el reponse
$errors = array();
//Se parsean los posibles errores generales del formulario(incluyendo los asserts a nivel de entidad)
foreach ($form->getErrors($deep, $flatten) as $key => $error) {
if ($form->isRoot()) {
$errors['form'][] = $error->getMessage();
} else {
$errors[] = $error->getMessage();
}
}
$childs = $form->getIterator();
//Se parsean los posibles errores de cada campo del formulario
/** @var Form $child */
foreach ($childs as $child) {
$fieldErrors = $child->getErrors();
while ($fieldErrors->current() != null) {
$errors[$child->getName()][] = $fieldErrors->current()->getMessage();
$fieldErrors->next();
}
}
return $errors;
}