/** * @param AbstractField|Group|Fieldset $element * * @return void */ private function addErrorClass($element) { if ($element instanceof Group || $element instanceof Fieldset) { foreach ($element->getFields() as $field) { if ($element instanceof Group || $element instanceof Fieldset) { $this->addErrorClass($field); } elseif ($field->isRequired()) { $field->addClass('has-error'); } } } elseif ($element->isRequired()) { $element->addClass('has-error'); } }
/** * @param Group|Fieldset|AbstractField $field * * @return array|Fields\AbstractField[] */ 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; }