From 80a068fd1b5da8dd0362cb4c5a450616d85ccd8a Mon Sep 17 00:00:00 2001 From: sukhwinder-somar Date: Wed, 16 Aug 2023 10:50:55 +1200 Subject: [PATCH 1/6] update finished function, issue-27 --- src/Control/ElementFormController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Control/ElementFormController.php b/src/Control/ElementFormController.php index 5f9ee1e..5faf49b 100644 --- a/src/Control/ElementFormController.php +++ b/src/Control/ElementFormController.php @@ -8,6 +8,7 @@ use SilverStripe\Core\Injector\Injector; use SilverStripe\UserForms\Control\UserDefinedFormController; use SilverStripe\UserForms\Form\UserForm; +use SilverStripe\CMS\Model\SiteTree; class ElementFormController extends ElementController { @@ -55,7 +56,11 @@ public function finished() $user->finished(); $page = $this->getPage(); - $controller = Injector::inst()->create($page->getControllerName(), $this->element->getPage()); + + while(!$page instanceof SiteTree) { + $page = $page->getPage(); + } + $controller = Injector::inst()->create($page->getControllerName(), $page->data()); $element = $this->element; return $controller->customise([ From 5c8b11bf17832c01b665b041b2bdcec74579ede6 Mon Sep 17 00:00:00 2001 From: sukhwinder-somar Date: Fri, 29 Sep 2023 11:54:56 +1300 Subject: [PATCH 2/6] check when page is null --- src/Control/ElementFormController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Control/ElementFormController.php b/src/Control/ElementFormController.php index 5faf49b..2f7ca4c 100644 --- a/src/Control/ElementFormController.php +++ b/src/Control/ElementFormController.php @@ -57,7 +57,11 @@ public function finished() $page = $this->getPage(); - while(!$page instanceof SiteTree) { + if ($page === null) { + return null; + } + + while(!$page instanceof SiteTree) { $page = $page->getPage(); } $controller = Injector::inst()->create($page->getControllerName(), $page->data()); From cf6a71129ccd625bf2cc9e92b068f83be8b794e1 Mon Sep 17 00:00:00 2001 From: sukhwinder-somar Date: Mon, 2 Oct 2023 08:48:43 +1300 Subject: [PATCH 3/6] return null in loop --- src/Control/ElementFormController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Control/ElementFormController.php b/src/Control/ElementFormController.php index 2f7ca4c..050ce9a 100644 --- a/src/Control/ElementFormController.php +++ b/src/Control/ElementFormController.php @@ -63,6 +63,10 @@ public function finished() while(!$page instanceof SiteTree) { $page = $page->getPage(); + + if ($page === null) { + return null; + } } $controller = Injector::inst()->create($page->getControllerName(), $page->data()); $element = $this->element; From 56cef2694a25f685519e3c0036a9898c9c9b0160 Mon Sep 17 00:00:00 2001 From: sukhwinder-somar Date: Tue, 10 Oct 2023 09:06:29 +1300 Subject: [PATCH 4/6] lint fixing --- src/Control/ElementFormController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Control/ElementFormController.php b/src/Control/ElementFormController.php index 050ce9a..1abd2c9 100644 --- a/src/Control/ElementFormController.php +++ b/src/Control/ElementFormController.php @@ -61,7 +61,7 @@ public function finished() return null; } - while(!$page instanceof SiteTree) { + while (!$page instanceof SiteTree) { $page = $page->getPage(); if ($page === null) { From 6882b199d90b8747992026512fcfaec30f3cd564 Mon Sep 17 00:00:00 2001 From: sukhwinder-somar Date: Tue, 10 Oct 2023 10:24:02 +1300 Subject: [PATCH 5/6] change inst to BaseElement instead of SiteTree --- src/Control/ElementFormController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Control/ElementFormController.php b/src/Control/ElementFormController.php index 1abd2c9..a19a4b2 100644 --- a/src/Control/ElementFormController.php +++ b/src/Control/ElementFormController.php @@ -2,13 +2,13 @@ namespace DNADesign\ElementalUserForms\Control; +use DNADesign\Elemental\Models\BaseElement; use DNADesign\Elemental\Controllers\ElementController; use SilverStripe\Control\Controller; use SilverStripe\Control\Director; use SilverStripe\Core\Injector\Injector; use SilverStripe\UserForms\Control\UserDefinedFormController; use SilverStripe\UserForms\Form\UserForm; -use SilverStripe\CMS\Model\SiteTree; class ElementFormController extends ElementController { @@ -61,7 +61,7 @@ public function finished() return null; } - while (!$page instanceof SiteTree) { + while ($page instanceof BaseElement) { $page = $page->getPage(); if ($page === null) { From 43427d741f245b0d75821f0d1f5d93126440426a Mon Sep 17 00:00:00 2001 From: sukhwinder-somar Date: Tue, 10 Oct 2023 12:25:35 +1300 Subject: [PATCH 6/6] remove handling of null --- src/Control/ElementFormController.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Control/ElementFormController.php b/src/Control/ElementFormController.php index a19a4b2..abd044b 100644 --- a/src/Control/ElementFormController.php +++ b/src/Control/ElementFormController.php @@ -57,16 +57,8 @@ public function finished() $page = $this->getPage(); - if ($page === null) { - return null; - } - while ($page instanceof BaseElement) { $page = $page->getPage(); - - if ($page === null) { - return null; - } } $controller = Injector::inst()->create($page->getControllerName(), $page->data()); $element = $this->element;