From 1ec6f86e8ef3a7c312758de49baddcbee5a71ff6 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 13 Oct 2015 18:00:43 +0200 Subject: [PATCH] IcingaObjectFieldForm: add delete button --- application/forms/IcingaObjectFieldForm.php | 26 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/application/forms/IcingaObjectFieldForm.php b/application/forms/IcingaObjectFieldForm.php index a4ce9733..923cfef7 100644 --- a/application/forms/IcingaObjectFieldForm.php +++ b/application/forms/IcingaObjectFieldForm.php @@ -60,8 +60,28 @@ class IcingaObjectFieldForm extends DirectorObjectForm ) )); - $this->setSubmitLabel( - $this->translate('Add new field') - ); + if ($this->object === null) { + $this->setSubmitLabel( + $this->translate('Add new field') + ); + } else { + $this->setSubmitLabel( + $this->translate('Store') + ); + $this->addElement('submit', 'delete', array( + 'label' => $this->translate('Delete') + )); + } + } + + protected function onRequest() + { + parent::onRequest(); + + if ($this->getSentValue('delete') === $this->translate('Delete')) { + $this->object()->delete(); + $this->setSuccessUrl($this->getSuccessUrl()->without('field_id')); + $this->redirectOnSuccess($this->translate('Field has been removed')); + } } }