Example #1
0
 /**
  * Returns a string representation of all form errors (including children errors).
  *
  * This method should only be used in ajax calls.
  *
  * @param Form $form         The form to parse
  * @param bool $withChildren Do we parse the embedded forms
  *
  * @return string A string representation of all errors
  */
 public function getRecursiveReadableErrors($form, $withChildren = true, $translationDomain = null, $level = 0)
 {
     $errors = '';
     $translationDomain = $translationDomain ? $translationDomain : $form->getConfig()->getOption('translation_domain');
     //the errors of the fields
     foreach ($form->getErrors() as $error) {
         //the view contains the label identifier
         $view = $form->createView();
         $labelId = $view->vars['label'];
         //get the translated label
         if ($labelId !== null) {
             $label = $this->translator->trans($labelId, [], $translationDomain) . ' : ';
         } else {
             $label = '';
         }
         //in case of dev mode, we display the item that is a problem
         //getCause cames in Symfony 2.5 version, this is just a fallback to avoid BC with previous versions
         if ($this->debug && method_exists($error, 'getCause')) {
             $cause = $error->getCause();
             if ($cause !== null) {
                 $causePropertyPath = $cause->getPropertyPath();
                 $errors .= ' ' . $causePropertyPath;
             }
         }
         //add the error
         $errors .= $label . $this->translator->trans($error->getMessage(), [], $translationDomain) . "\n";
     }
     //do we parse the children
     if ($withChildren) {
         //we parse the children
         foreach ($form->getIterator() as $child) {
             $level++;
             if ($err = $this->getRecursiveReadableErrors($child, $withChildren, $translationDomain, $level)) {
                 $errors .= $err;
             }
         }
     }
     return $errors;
 }
 public function getViewParameters(BlockInterface $block)
 {
     $parameters = parent::getViewParameters($block);
     return array_merge($parameters, ['form' => $this->form->createView(), 'subscribed' => $this->subscribed]);
 }