From 41b1244295e591ca53c7bcc6a9d8d4d498e58de6 Mon Sep 17 00:00:00 2001 From: Simon Gadient Date: Wed, 9 Feb 2022 12:10:21 +0100 Subject: [PATCH 1/4] BUGFIX: configured base uri in form action uri --- Classes/ViewHelpers/FormViewHelper.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Classes/ViewHelpers/FormViewHelper.php b/Classes/ViewHelpers/FormViewHelper.php index 48efba0..129c5b3 100644 --- a/Classes/ViewHelpers/FormViewHelper.php +++ b/Classes/ViewHelpers/FormViewHelper.php @@ -11,6 +11,8 @@ * source code. */ +use Neos\Flow\Annotations as Flow; +use Neos\Flow\Http\BaseUriProvider; use Neos\Flow\Mvc\ActionRequest; use Neos\FluidAdaptor\ViewHelpers\FormViewHelper as FluidFormViewHelper; use Neos\Form\Core\Runtime\FormRuntime; @@ -21,6 +23,13 @@ */ class FormViewHelper extends FluidFormViewHelper { + + /** + * @Flow\Inject + * @var BaseUriProvider + */ + protected $baseUriProvider; + /** * Renders hidden form fields for referrer information about * the current request. @@ -58,10 +67,15 @@ protected function getFormObjectName() protected function getFormActionUri() { /** @var ActionRequest $actionRequest */ - $actionRequest = $this->controllerContext->getRequest(); - $uri = $actionRequest->getHttpRequest()->getUri(); - if ($this->hasArgument('section') && $this->arguments['section'] !== '') { - $uri = $uri->withFragment($this->arguments['section']); + $actionRequest = clone $this->controllerContext->getRequest(); + $requestUri = $actionRequest->getHttpRequest()->getUri(); + $uri = $this->baseUriProvider->getConfiguredBaseUriOrFallbackToCurrentRequest() + ->withPath($requestUri->getPath()) + ->withQuery($requestUri->getQuery()) + ->withFragment($requestUri->getFragment()); + + if ($this->hasArgument('section')) { + $uri = preg_replace('/#.*$/', '', $uri) . '#' . $this->arguments['section']; } return (string)$uri; } From 8f1dc64a2b36183269e4d819eb023a33583b2c1f Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Tue, 13 Sep 2022 14:45:19 +0200 Subject: [PATCH 2/4] Apply suggestions from code review --- Classes/ViewHelpers/FormViewHelper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Classes/ViewHelpers/FormViewHelper.php b/Classes/ViewHelpers/FormViewHelper.php index 129c5b3..6c96cc6 100644 --- a/Classes/ViewHelpers/FormViewHelper.php +++ b/Classes/ViewHelpers/FormViewHelper.php @@ -67,12 +67,12 @@ protected function getFormObjectName() protected function getFormActionUri() { /** @var ActionRequest $actionRequest */ - $actionRequest = clone $this->controllerContext->getRequest(); - $requestUri = $actionRequest->getHttpRequest()->getUri(); - $uri = $this->baseUriProvider->getConfiguredBaseUriOrFallbackToCurrentRequest() + $httpRequest = $this->controllerContext->getRequest()->getHttpRequest(); + $requestUri = $httpRequest->getUri(); + $uri = $this->baseUriProvider->getConfiguredBaseUriOrFallbackToCurrentRequest($httpRequest) ->withPath($requestUri->getPath()) ->withQuery($requestUri->getQuery()) - ->withFragment($requestUri->getFragment()); + ->withFragment($this->hasArgument('section') ? $this->arguments['section'] : $requestUri->getFragment()); if ($this->hasArgument('section')) { $uri = preg_replace('/#.*$/', '', $uri) . '#' . $this->arguments['section']; From f2430a6e3c1871ed547892ca0f6a986bed95b737 Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Tue, 13 Sep 2022 14:48:55 +0200 Subject: [PATCH 3/4] Update Classes/ViewHelpers/FormViewHelper.php --- Classes/ViewHelpers/FormViewHelper.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Classes/ViewHelpers/FormViewHelper.php b/Classes/ViewHelpers/FormViewHelper.php index 6c96cc6..59e6f44 100644 --- a/Classes/ViewHelpers/FormViewHelper.php +++ b/Classes/ViewHelpers/FormViewHelper.php @@ -73,9 +73,6 @@ protected function getFormActionUri() ->withPath($requestUri->getPath()) ->withQuery($requestUri->getQuery()) ->withFragment($this->hasArgument('section') ? $this->arguments['section'] : $requestUri->getFragment()); - - if ($this->hasArgument('section')) { - $uri = preg_replace('/#.*$/', '', $uri) . '#' . $this->arguments['section']; } return (string)$uri; } From cc849aad3a89ed8569a7188a82689686d7b9fef9 Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Tue, 13 Sep 2022 14:52:41 +0200 Subject: [PATCH 4/4] Update Classes/ViewHelpers/FormViewHelper.php --- Classes/ViewHelpers/FormViewHelper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Classes/ViewHelpers/FormViewHelper.php b/Classes/ViewHelpers/FormViewHelper.php index 59e6f44..7b86596 100644 --- a/Classes/ViewHelpers/FormViewHelper.php +++ b/Classes/ViewHelpers/FormViewHelper.php @@ -73,7 +73,6 @@ protected function getFormActionUri() ->withPath($requestUri->getPath()) ->withQuery($requestUri->getQuery()) ->withFragment($this->hasArgument('section') ? $this->arguments['section'] : $requestUri->getFragment()); - } return (string)$uri; } }