From 1f5d38a8b988126d22608e69d750374fce66c353 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 10 Oct 2022 15:30:15 +0000 Subject: [PATCH 1/2] - Added some more information into the form context whether a form was sent, and what was it's return value (if there was any) --- src/Method/FormContext.php | 4 +++- src/Method/FormHandler.php | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Method/FormContext.php b/src/Method/FormContext.php index fe10aad..2d5cde4 100644 --- a/src/Method/FormContext.php +++ b/src/Method/FormContext.php @@ -13,6 +13,8 @@ class FormContext implements FormContextInterface public bool $formExecuted = false; + public /*mixed*/ $formExecutionStatus = null; + public array $values = []; public array $files = []; @@ -64,7 +66,7 @@ class FormContext implements FormContextInterface public function formSent() : bool { - $valid = true; + $valid = in_array($this->request->getMethod(), [ 'POST', 'PUT', 'PATCH', 'DELETE', ]); if ( ! $this->skipCsrf && ($this->formName ?? false) ) { $token = $this->get('picea-ui-form')[$this->formName] ?? false; diff --git a/src/Method/FormHandler.php b/src/Method/FormHandler.php index e5a25c3..6ad3864 100644 --- a/src/Method/FormHandler.php +++ b/src/Method/FormHandler.php @@ -13,7 +13,7 @@ class FormHandler { public bool $validateCsrfToken = true; - public ? bool $executionStatus = null; + public /* mixed */ $executionStatus = null; public ? bool $validationStatus = null; @@ -38,8 +38,8 @@ class FormHandler { $this->context = method_exists($form, 'getContext') ? $form->getContext($request) : new FormContext($request); } - $this->request->context = $this->context; - + $this->request->withAttribute('picea.context', $this->context); + $this->initialize(); } @@ -49,7 +49,8 @@ class FormHandler { if ( $this->sent && $this->context->formSent() ) { if ( $this->validationStatus = $this->form->validate($this->context) ) { - $this->executionStatus = $this->form->execute($this->context); + $this->context->formExecutionStatus = $this->executionStatus = $this->form->execute($this->context); + $this->context->formExecuted = true; } } } From bd501bce867f823298ccc9670ad3c023fc0a2e2a Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 11 Nov 2022 13:58:22 +0000 Subject: [PATCH 2/2] - Added the multiple value selection --- src/Form/UiSelect.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Form/UiSelect.php b/src/Form/UiSelect.php index 499fc4b..9e1d937 100644 --- a/src/Form/UiSelect.php +++ b/src/Form/UiSelect.php @@ -79,6 +79,11 @@ class UiSelect extends UiElement implements Extension { protected function isSelected($check, $value, bool $strict = true) : bool { + if ( is_array($value) ) { + return in_array($check, $value, $strict); + } + + return $strict ? $check === $value : $check == $value; } }