Created
November 6, 2018 16:03
-
-
Save mfMeds/efd0b9130ab75957d19d46be40de6bd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MediateSystems\Website\Finisher; | |
use Neos\Flow\Annotations as Flow; | |
use Neos\Flow\Mvc\ActionRequest; | |
use Neos\Form\Core\Model\AbstractFinisher; | |
use Neos\Neos\Service\LinkingService; | |
use Neos\ContentRepository\Domain\Model\NodeInterface; | |
use Neos\Fusion\ViewHelpers\FusionContextTrait; | |
use Neos\Flow\Mvc\Routing\UriBuilder; | |
use Neos\Flow\Mvc\Controller\ControllerContext; | |
use Neos\Flow\Mvc\Controller\Arguments; | |
class MultiLangFinisher extends AbstractFinisher | |
{ | |
use FusionContextTrait; | |
/** | |
* @Flow\Inject | |
* @var \Neos\ContentRepository\Domain\Service\ContextFactoryInterface | |
*/ | |
protected $contextFactory; | |
/** | |
* @Flow\Inject | |
* @var LinkingService | |
*/ | |
protected $linkingService; | |
/** | |
* @var array | |
*/ | |
protected $defaultOptions = [ | |
'redirectTo' => '', | |
'delay' => 0, | |
'statusCode' => 303 | |
]; | |
/** | |
* @Flow\Inject | |
* @var \Neos\Flow\I18n\Service | |
*/ | |
protected $i18nService; | |
/** | |
* @var \Neos\Flow\Mvc\Routing\UriBuilder | |
*/ | |
protected $uriBuilder; | |
private function injectUriBuilder($request) { | |
$uriBuilder = new \NEOS\Flow\Mvc\Routing\UriBuilder(); | |
$uriBuilder->setRequest($request); | |
$uriBuilder->setCreateAbsoluteUri(true); | |
$this->uriBuilder = $uriBuilder; | |
} | |
private function getUrlForIdentifier(string $identifier) { | |
$context = $this->contextFactory->create( | |
[ | |
'workspaceName' => 'live', | |
'dimensions' => [ 'language' => [(string)$this->i18nService->getConfiguration()->getCurrentLocale()] ], | |
] | |
); | |
$node = $context->getNodeByIdentifier($identifier); | |
return $this->linkingService->createNodeUri( | |
new ControllerContext( | |
$this->uriBuilder->getRequest(), | |
new \NEOS\Flow\Http\Response(), | |
new \NEOS\Flow\Mvc\Controller\Arguments(array()), | |
$this->uriBuilder | |
), | |
$node, | |
$context->getRootNode(), | |
'html', | |
true | |
); | |
} | |
public function executeInternal() | |
{ | |
$formRuntime = $this->finisherContext->getFormRuntime(); | |
$request = $formRuntime->getRequest(); | |
$this->injectUriBuilder($request); | |
$identifier = $this->parseOption('redirectTo'); | |
try { | |
Header("Location: ".$this->getUrlForIdentifier($identifier)); | |
} catch(\Exception $e) { | |
echo $e->xdebug_message; | |
die(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment