[Form] refactor Form::bind to save 7 assignments
This commit is contained in:
parent
a1e6cfbe15
commit
8d45539eac
@ -420,7 +420,6 @@ class Form implements \IteratorAggregate, FormInterface
|
|||||||
$this->modelData = $modelData;
|
$this->modelData = $modelData;
|
||||||
$this->normData = $normData;
|
$this->normData = $normData;
|
||||||
$this->viewData = $viewData;
|
$this->viewData = $viewData;
|
||||||
$this->synchronized = true;
|
|
||||||
$this->initialized = true;
|
$this->initialized = true;
|
||||||
$this->lockSetData = false;
|
$this->lockSetData = false;
|
||||||
|
|
||||||
@ -546,10 +545,6 @@ class Form implements \IteratorAggregate, FormInterface
|
|||||||
// errors added during listeners
|
// errors added during listeners
|
||||||
$this->errors = array();
|
$this->errors = array();
|
||||||
|
|
||||||
$modelData = null;
|
|
||||||
$normData = null;
|
|
||||||
$extraData = array();
|
|
||||||
$synchronized = false;
|
|
||||||
$dispatcher = $this->config->getEventDispatcher();
|
$dispatcher = $this->config->getEventDispatcher();
|
||||||
|
|
||||||
// Hook to change content of the data bound by the browser
|
// Hook to change content of the data bound by the browser
|
||||||
@ -561,9 +556,6 @@ class Form implements \IteratorAggregate, FormInterface
|
|||||||
$submittedData = $event->getData();
|
$submittedData = $event->getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// By default, the submitted data is also the data in view format
|
|
||||||
$viewData = $submittedData;
|
|
||||||
|
|
||||||
// Check whether the form is compound.
|
// Check whether the form is compound.
|
||||||
// This check is preferrable over checking the number of children,
|
// This check is preferrable over checking the number of children,
|
||||||
// since forms without children may also be compound.
|
// since forms without children may also be compound.
|
||||||
@ -587,14 +579,17 @@ class Form implements \IteratorAggregate, FormInterface
|
|||||||
if ($this->has($name)) {
|
if ($this->has($name)) {
|
||||||
$this->children[$name]->bind($value);
|
$this->children[$name]->bind($value);
|
||||||
} else {
|
} else {
|
||||||
$extraData[$name] = $value;
|
$this->extraData[$name] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the form is compound, the default data in view format
|
// If the form is compound, the default data in view format
|
||||||
// is reused. The data of the children is merged into this
|
// is reused. The data of the children is merged into this
|
||||||
// default data using the data mapper.
|
// default data using the data mapper.
|
||||||
$viewData = $this->getViewData();
|
$viewData = $this->viewData;
|
||||||
|
} else {
|
||||||
|
// If the form is not compound, the submitted data is also the data in view format.
|
||||||
|
$viewData = $submittedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FormUtil::isEmpty($viewData)) {
|
if (FormUtil::isEmpty($viewData)) {
|
||||||
@ -615,6 +610,9 @@ class Form implements \IteratorAggregate, FormInterface
|
|||||||
$this->config->getDataMapper()->mapFormsToData($this->children, $viewData);
|
$this->config->getDataMapper()->mapFormsToData($this->children, $viewData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$modelData = null;
|
||||||
|
$normData = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Normalize data to unified representation
|
// Normalize data to unified representation
|
||||||
$normData = $this->viewToNorm($viewData);
|
$normData = $this->viewToNorm($viewData);
|
||||||
@ -632,17 +630,14 @@ class Form implements \IteratorAggregate, FormInterface
|
|||||||
// Synchronize representations - must not change the content!
|
// Synchronize representations - must not change the content!
|
||||||
$modelData = $this->normToModel($normData);
|
$modelData = $this->normToModel($normData);
|
||||||
$viewData = $this->normToView($normData);
|
$viewData = $this->normToView($normData);
|
||||||
|
|
||||||
$synchronized = true;
|
|
||||||
} catch (TransformationFailedException $e) {
|
} catch (TransformationFailedException $e) {
|
||||||
|
$this->synchronized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->bound = true;
|
$this->bound = true;
|
||||||
$this->modelData = $modelData;
|
$this->modelData = $modelData;
|
||||||
$this->normData = $normData;
|
$this->normData = $normData;
|
||||||
$this->viewData = $viewData;
|
$this->viewData = $viewData;
|
||||||
$this->extraData = $extraData;
|
|
||||||
$this->synchronized = $synchronized;
|
|
||||||
|
|
||||||
if ($dispatcher->hasListeners(FormEvents::POST_BIND)) {
|
if ($dispatcher->hasListeners(FormEvents::POST_BIND)) {
|
||||||
$event = new FormEvent($this, $viewData);
|
$event = new FormEvent($this, $viewData);
|
||||||
|
Reference in New Issue
Block a user