[Form] Simplified code in MergeCollectionListener

This commit is contained in:
Bernhard Schussek 2012-02-02 13:58:41 +01:00
parent 8ab982afc8
commit 8714d7924e
1 changed files with 7 additions and 9 deletions

View File

@ -98,28 +98,26 @@ class MergeCollectionListener implements EventSubscriberInterface
// Check if the parent has matching methods to add/remove items
if ($this->useAccessors && is_object($parentData)) {
$reflClass = new \ReflectionClass($parentData);
$addMethodNeeded = $this->allowAdd && !$this->addMethod;
$removeMethodNeeded = $this->allowDelete && !$this->removeMethod;
// Any of the two methods is required, but not yet known
if (($this->allowAdd && !$this->addMethod) || ($this->allowDelete && !$this->removeMethod)) {
$plural = ucfirst($form->getName());
$singulars = (array) FormUtil::singularify($plural);
if ($addMethodNeeded || $removeMethodNeeded) {
$singulars = (array) FormUtil::singularify(ucfirst($form->getName()));
foreach ($singulars as $singular) {
// Try to find adder, but don't override preconfigured one
if ($this->allowAdd && !$this->addMethod) {
if ($addMethodNeeded) {
$addMethod = $this->checkMethod($reflClass, 'add' . $singular);
}
// Try to find remover, but don't override preconfigured one
if ($this->allowDelete && !$this->removeMethod) {
if ($removeMethodNeeded) {
$removeMethod = $this->checkMethod($reflClass, 'remove' . $singular);
}
$addMethodFound = !$this->allowAdd || $addMethod || $this->addMethod;
$removeMethodFound = !$this->allowDelete || $removeMethod || $this->removeMethod;
// Found all that we need. Abort search.
if ($addMethodFound && $removeMethodFound) {
if ((!$addMethodNeeded || $addMethod) && (!$removeMethodNeeded || $removeMethod)) {
break;
}