Skip to content

Instantly share code, notes, and snippets.

@mfMeds
Created November 6, 2018 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfMeds/efd0b9130ab75957d19d46be40de6bd3 to your computer and use it in GitHub Desktop.
Save mfMeds/efd0b9130ab75957d19d46be40de6bd3 to your computer and use it in GitHub Desktop.
<?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