Skip to content

Commit

Permalink
allow setting custom route for redirect controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ameotoko committed Nov 1, 2021
1 parent 5a29ffd commit 1b39a10
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getBundles(ParserInterface $parser): array

public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel)
{
$routes = __DIR__ . '/../Resources/config/routes.yaml';
$routes = __DIR__ . '/../Resources/config/routing.yaml';

return $resolver->resolve($routes)->load($routes);
}
Expand Down
9 changes: 4 additions & 5 deletions src/Controller/RedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouterInterface;

class RedirectController
{
public function __invoke(Request $request, ContaoFramework $framework): Response
public function __invoke(Request $request, ContaoFramework $framework, RouterInterface $router): Response
{
// required for REQUEST_TOKEN to be defined
$framework->initialize();
$url = $router->generate('contao_backend');

if ($srcQuery = $request->getQueryString()) {
$targetQuery = str_replace('/redirect', '', Backend::addToUrl($srcQuery));
$url = '/' . StringUtil::ampersand($targetQuery, false);
} else {
$url = '/contao';
$url = StringUtil::ampersand(str_replace($request->getPathInfo(), $url, '/' . Backend::addToUrl($srcQuery)), false);
}

return new RedirectResponse($url);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ameotoko_backend_redirect:
path: /contao/redirect
path: /
controller: Ameotoko\BackendRedirect\Controller\RedirectController
defaults:
_scope: backend
5 changes: 5 additions & 0 deletions src/Resources/config/routing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_ameotoko_backend_redirect:
resource: './_definition.yaml'
prefix: /contao/redirect
trailing_slash_on_root: false

0 comments on commit 1b39a10

Please sign in to comment.