Example #1
0
 /**
  * @return array
  */
 public function findErrors()
 {
     $formErrors = method_exists($this->form, 'getAllErrors') ? $this->form->getAllErrors() : $this->form->getErrors();
     if (!$formErrors) {
         return array();
     }
     $form = $this->form;
     $translate = function ($errors) use($form) {
         if ($translator = $form->getTranslator()) {
             // If we have translator, translate!
             foreach ($errors as $key => $val) {
                 $errors[$key] = $translator->translate($val);
             }
         }
         return $errors;
     };
     if (!$this->errorsAtInputs) {
         return $translate($formErrors);
     }
     if (method_exists($this->form, 'getAllErrors')) {
         return $translate($this->form->getErrors());
     }
     foreach ($this->form->getControls() as $control) {
         /** @var \Nette\Forms\Controls\BaseControl $control */
         if (!$control->hasErrors()) {
             continue;
         }
         $formErrors = array_diff($formErrors, $control->getErrors());
     }
     return $translate($formErrors);
 }