Skip to content

Commit

Permalink
FEATURE: Allow to set a specific URL for the redirect finisher
Browse files Browse the repository at this point in the history
This change adds the option to allow a specific URL
to be set for the redirect finisher. Also some cleanup /
refactoring is done.
  • Loading branch information
daniellienert committed May 24, 2016
1 parent a1f4632 commit a02118b
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions Classes/TYPO3/Form/Finishers/RedirectFinisher.php
Expand Up @@ -10,23 +10,26 @@
* *
* The TYPO3 project - inspiring people to share! *
* */
use TYPO3\Flow\Mvc\Routing\UriBuilder;
use TYPO3\Form\Core\Model\AbstractFinisher;

/**
* This finisher redirects to another Controller.
* This finisher redirects to another Controller or a specific URI.
*/
class RedirectFinisher extends \TYPO3\Form\Core\Model\AbstractFinisher
class RedirectFinisher extends AbstractFinisher
{
/**
* @var array
*/
protected $defaultOptions = array(
protected $defaultOptions = [
'package' => null,
'controller' => null,
'action' => '',
'arguments' => array(),
'arguments' => [],
'uri' => '',
'delay' => 0,
'statusCode' => 303,
);
'statusCode' => 303
];

/**
* Executes this finisher
Expand All @@ -40,23 +43,20 @@ public function executeInternal()
$formRuntime = $this->finisherContext->getFormRuntime();
$request = $formRuntime->getRequest()->getMainRequest();

$packageKey = $this->parseOption('package');
$controllerName = $this->parseOption('controller');
$actionName = $this->parseOption('action');
$arguments = $this->parseOption('arguments');
$delay = (integer)$this->parseOption('delay');
$statusCode = $this->parseOption('statusCode');
$uri = $this->parseOption('uri');

$subpackageKey = null;
if ($packageKey !== null && strpos($packageKey, '\\') !== false) {
list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2);

if($uri === '') {
$uri = $this->buildActionUri($request);
}

$uriParts = parse_url($uri);
if(!isset($uriParts['scheme']) || $uriParts['scheme'] === '') {
$uri = $request->getHttpRequest()->getBaseUri() . $uri;
}
$uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder();
$uriBuilder->setRequest($request);
$uriBuilder->reset();

$uri = $uriBuilder->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey);
$uri = $request->getHttpRequest()->getBaseUri() . $uri;
$escapedUri = htmlentities($uri, ENT_QUOTES, 'utf-8');

$response = $formRuntime->getResponse();
Expand All @@ -80,4 +80,28 @@ public function setOptions(array $options)
{
$this->options = $options;
}

/**
* @param $request
* @return string
* @throws \TYPO3\Flow\Mvc\Routing\Exception\MissingActionNameException
*/
protected function buildActionUri($request)
{
$packageKey = $this->parseOption('package');
$controllerName = $this->parseOption('controller');
$actionName = $this->parseOption('action');
$arguments = $this->parseOption('arguments');

$subpackageKey = null;
if ($packageKey !== null && strpos($packageKey, '\\') !== false) {
list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2);
}
$uriBuilder = new UriBuilder();
$uriBuilder->setRequest($request);
$uriBuilder->reset();

$uri = $uriBuilder->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey);
return $uri;
}
}

0 comments on commit a02118b

Please sign in to comment.