From e7687d226a4cb10e8fdca868d05d22c9b4e8e5df Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 15 Oct 2015 20:16:07 +0200 Subject: [PATCH] DirectorObjectForm: provide delete button --- .../Director/Web/Form/DirectorObjectForm.php | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index ddedb72e..c82d77ce 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -16,6 +16,8 @@ abstract class DirectorObjectForm extends QuickForm protected $className; + protected $deleteButtonName; + protected $objectType = 'object'; protected $fieldsDisplayGroup; @@ -482,8 +484,33 @@ abstract class DirectorObjectForm extends QuickForm } $this->handleProperties($object, $values); + } - $this->moveSubmitToBottom(); + protected function addDeleteButton($label = null) + { + if ($label === null) { + $label = $this->translate('Delete'); + } + + $el = $this->createElement('submit', $label)->setLabel($label)->setDecorators(array('ViewHelper')); //->removeDecorator('Label'); + + $this->deleteButtonName = $el->getName(); + $this->addElement($el); + + return $this; + } + + public function hasDeleteButton() + { + return $this->deleteButtonName !== null; + } + + public function shouldBeDeleted() + { + if (! $this->hasDeleteButton()) return false; + + $name = $this->deleteButtonName; + return $this->getSentValue($name) === $this->getElement($name)->getLabel(); } public function loadObject($id)