From d9431957322db45a248b679e957c9f7abbc59397 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sat, 14 Nov 2015 14:45:48 +0100 Subject: [PATCH] DirectorObjectForm: separate deletion logic --- .../Director/Web/Form/DirectorObjectForm.php | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index 61a52442..59b2b8d5 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -495,28 +495,7 @@ abstract class DirectorObjectForm extends QuickForm $object = $this->object(); if ($this->shouldBeDeleted()) { - $key = $object->getKeyName(); - if ($object instanceof IcingaObject) { - $msg = sprintf( - '%s "%s" has been removed', - $this->translate($this->getObjectName()), - $object->object_name - ); - } else { - $msg = sprintf( - '%s has been removed', - $this->translate($this->getObjectName()) - ); - } - - if ($object->delete()) { - // fields? $this->setSuccessUrl($this->getSuccessUrl()->without($key)); - if ($object instanceof IcingaObject) { - $this->setSuccessUrl('director/' . $object->getShortTableName() . 's'); - } - } - // TODO: show object name and so - $this->redirectOnSuccess($msg); + $this->deleteObject($object); } if ($this->hasBeenSent()) { @@ -542,6 +521,32 @@ abstract class DirectorObjectForm extends QuickForm $this->handleProperties($object, $values); } + protected function deleteObject($object) + { + $key = $object->getKeyName(); + if ($object instanceof IcingaObject) { + $msg = sprintf( + '%s "%s" has been removed', + $this->translate($this->getObjectName()), + $object->object_name + ); + } else { + $msg = sprintf( + '%s has been removed', + $this->translate($this->getObjectName()) + ); + } + + if ($object->delete()) { + // fields? $this->setSuccessUrl($this->getSuccessUrl()->without($key)); + if ($object instanceof IcingaObject) { + $this->setSuccessUrl('director/' . $object->getShortTableName() . 's'); + } + } + // TODO: show object name and so + $this->redirectOnSuccess($msg); + } + protected function addDeleteButton($label = null) { if ($label === null) {