|
@@ -83,6 +83,7 @@ class Form implements \IteratorAggregate, FormInterface
|
|
|
|
|
|
private $dataMapper;
|
|
|
private $errors = array();
|
|
|
+ private $errorBubbling;
|
|
|
private $name = '';
|
|
|
private $parent;
|
|
|
private $bound = false;
|
|
@@ -110,7 +111,8 @@ class Form implements \IteratorAggregate, FormInterface
|
|
|
FormRendererInterface $renderer = null, DataTransformerInterface $clientTransformer = null,
|
|
|
DataTransformerInterface $normTransformer = null,
|
|
|
DataMapperInterface $dataMapper = null, array $validators = array(),
|
|
|
- $required = false, $readOnly = false, array $attributes = array())
|
|
|
+ $required = false, $readOnly = false, $errorBubbling = false,
|
|
|
+ array $attributes = array())
|
|
|
{
|
|
|
foreach ($validators as $validator) {
|
|
|
if (!$validator instanceof FormValidatorInterface) {
|
|
@@ -128,6 +130,7 @@ class Form implements \IteratorAggregate, FormInterface
|
|
|
$this->required = $required;
|
|
|
$this->readOnly = $readOnly;
|
|
|
$this->attributes = $attributes;
|
|
|
+ $this->errorBubbling = $errorBubbling;
|
|
|
|
|
|
if ($renderer) {
|
|
|
$renderer->setForm($this);
|
|
@@ -136,11 +139,11 @@ class Form implements \IteratorAggregate, FormInterface
|
|
|
$this->setData(null);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Cloning is not supported
|
|
|
- */
|
|
|
- private function __clone()
|
|
|
+ public function __clone()
|
|
|
{
|
|
|
+ foreach ($this->children as $key => $child) {
|
|
|
+ $this->children[$key] = clone $child;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -414,7 +417,21 @@ class Form implements \IteratorAggregate, FormInterface
|
|
|
*/
|
|
|
public function addError(FormError $error)
|
|
|
{
|
|
|
- $this->errors[] = $error;
|
|
|
+ if ($this->parent && $this->errorBubbling) {
|
|
|
+ $this->parent->addError($error);
|
|
|
+ } else {
|
|
|
+ $this->errors[] = $error;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns whether errors bubble up to the parent
|
|
|
+ *
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
+ public function getErrorBubbling()
|
|
|
+ {
|
|
|
+ return $this->errorBubbling;
|
|
|
}
|
|
|
|
|
|
/**
|