From c47a84730537dab66756c28c60e0db167b6b1031 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 11 Mar 2022 16:52:28 +0100 Subject: [PATCH] Forms: Introduce `RemoveHomePaneForm` class --- .../forms/Dashboard/RemoveHomePaneForm.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 application/forms/Dashboard/RemoveHomePaneForm.php diff --git a/application/forms/Dashboard/RemoveHomePaneForm.php b/application/forms/Dashboard/RemoveHomePaneForm.php new file mode 100644 index 000000000..c29818f1c --- /dev/null +++ b/application/forms/Dashboard/RemoveHomePaneForm.php @@ -0,0 +1,45 @@ +dashboard = $dashboard; + + $this->setAction((string) Url::fromRequest()); + } + + protected function assemble() + { + $this->addElement('submit', 'btn_remove', ['label' => t('Remove Home')]); + } + + protected function onSuccess() + { + $requestUrl = Url::fromRequest(); + $home = $this->dashboard->getActiveHome(); + + if ($requestUrl->getPath() === Dashboard::BASE_ROUTE . '/remove-home') { + $this->dashboard->removeHome($home); + + Notification::success(sprintf(t('Removed dashboard home "%s" successfully'), $home->getLabel())); + } else { + $pane = $home->getPane($requestUrl->getParam('pane')); + $home->removePane($pane); + + Notification::success(sprintf(t('Removed dashboard pane "%s" successfully'), $pane->getTitle())); + } + } +}