[Form] Simplified code in MergeCollectionListener
This commit is contained in:
parent
8ab982afc8
commit
8714d7924e
@ -98,28 +98,26 @@ class MergeCollectionListener implements EventSubscriberInterface
|
|||||||
// Check if the parent has matching methods to add/remove items
|
// Check if the parent has matching methods to add/remove items
|
||||||
if ($this->useAccessors && is_object($parentData)) {
|
if ($this->useAccessors && is_object($parentData)) {
|
||||||
$reflClass = new \ReflectionClass($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
|
// Any of the two methods is required, but not yet known
|
||||||
if (($this->allowAdd && !$this->addMethod) || ($this->allowDelete && !$this->removeMethod)) {
|
if ($addMethodNeeded || $removeMethodNeeded) {
|
||||||
$plural = ucfirst($form->getName());
|
$singulars = (array) FormUtil::singularify(ucfirst($form->getName()));
|
||||||
$singulars = (array) FormUtil::singularify($plural);
|
|
||||||
|
|
||||||
foreach ($singulars as $singular) {
|
foreach ($singulars as $singular) {
|
||||||
// Try to find adder, but don't override preconfigured one
|
// Try to find adder, but don't override preconfigured one
|
||||||
if ($this->allowAdd && !$this->addMethod) {
|
if ($addMethodNeeded) {
|
||||||
$addMethod = $this->checkMethod($reflClass, 'add' . $singular);
|
$addMethod = $this->checkMethod($reflClass, 'add' . $singular);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find remover, but don't override preconfigured one
|
// Try to find remover, but don't override preconfigured one
|
||||||
if ($this->allowDelete && !$this->removeMethod) {
|
if ($removeMethodNeeded) {
|
||||||
$removeMethod = $this->checkMethod($reflClass, 'remove' . $singular);
|
$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.
|
// Found all that we need. Abort search.
|
||||||
if ($addMethodFound && $removeMethodFound) {
|
if ((!$addMethodNeeded || $addMethod) && (!$removeMethodNeeded || $removeMethod)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user