Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!! TASK: Use configured baseUri in form action #100

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Classes/ViewHelpers/FormViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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']);
$httpRequest = $this->controllerContext->getRequest()->getHttpRequest();
$requestUri = $httpRequest->getUri();
$uri = $this->baseUriProvider->getConfiguredBaseUriOrFallbackToCurrentRequest($httpRequest)
->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'];
bwaidelich marked this conversation as resolved.
Show resolved Hide resolved
bwaidelich marked this conversation as resolved.
Show resolved Hide resolved
}
bwaidelich marked this conversation as resolved.
Show resolved Hide resolved
return (string)$uri;
}
Expand Down