From dcaf62573cf6323e30238eb093eb61c3b4e29319 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 11 Mar 2022 16:51:07 +0100 Subject: [PATCH] Forms: Introduce `RemoveDashletForm` class --- .../forms/Dashboard/RemoveDashletForm.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 application/forms/Dashboard/RemoveDashletForm.php diff --git a/application/forms/Dashboard/RemoveDashletForm.php b/application/forms/Dashboard/RemoveDashletForm.php new file mode 100644 index 000000000..a5dbd2b25 --- /dev/null +++ b/application/forms/Dashboard/RemoveDashletForm.php @@ -0,0 +1,46 @@ +dashboard = $dashboard; + + $this->setAction((string) Url::fromRequest()); + } + + protected function assemble() + { + $this->addHtml(HtmlElement::create('h1', null, sprintf( + t('Please confirm removal of dashlet "%s"'), + Url::fromRequest()->getParam('dashlet') + ))); + + $this->addElement('submit', 'remove_dashlet', ['label' => t('Remove Dashlet')]); + } + + protected function onSuccess() + { + $requestUrl = Url::fromRequest(); + $home = $this->dashboard->getActiveHome(); + $pane = $home->getPane($requestUrl->getParam('pane')); + + $dashlet = $requestUrl->getParam('dashlet'); + $pane->removeDashlet($dashlet); + + Notification::success(sprintf(t('Removed dashlet "%s" successfully'), $dashlet)); + } +}