This repository was archived by the owner on Apr 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Make redirect url fallback configurable #190
Open
AsfalothDE
wants to merge
11
commits into
liip:master
Choose a base branch
from
AsfalothDE:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2bfbe41
Make redirect url fallback configurable
e961202
Fix unit tests
92ba4e6
Use / as fallback when there is no route given
3b49d2c
Fix missing $this…
ef72908
Make statement CS compliant
741ca10
Remove redundant code
ab6eb14
Set default value of redirect_fallback to null
be1e60d
Draft for routing test
7537a58
fixed tests by removing the Request mock
lsmith77 08aef0e
Merge pull request #1 from liip/AsfalothDE-master
AsfalothDE 068dbb0
Add documentation for redirect_fallback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\RedirectResponse; | ||
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
| use Symfony\Component\Routing\RouterInterface; | ||
|
|
||
| /** | ||
| * Theme controller. | ||
|
|
@@ -40,18 +41,32 @@ class ThemeController | |
| */ | ||
| protected $cookieOptions; | ||
|
|
||
| /** | ||
| * @var RouterInterface | ||
| */ | ||
| protected $router; | ||
|
|
||
| /** | ||
| * @var string|null | ||
| */ | ||
| protected $defaultRoute; | ||
|
|
||
| /** | ||
| * Theme controller construct. | ||
| * | ||
| * @param ActiveTheme $activeTheme active theme instance | ||
| * @param array $themes Available themes | ||
| * @param array|null $cookieOptions The options of the cookie we look for the theme to set | ||
| * @param RouterInterface $router | ||
| * @param string|null $defaultRoute | ||
| */ | ||
| public function __construct(ActiveTheme $activeTheme, array $themes, array $cookieOptions = null) | ||
| public function __construct(ActiveTheme $activeTheme, array $themes, array $cookieOptions = null, RouterInterface $router, $defaultRoute = null) | ||
| { | ||
| $this->activeTheme = $activeTheme; | ||
| $this->themes = $themes; | ||
| $this->cookieOptions = $cookieOptions; | ||
| $this->router = $router; | ||
| $this->defaultRoute = $defaultRoute; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -73,7 +88,15 @@ public function switchAction(Request $request) | |
|
|
||
| $this->activeTheme->setName($theme); | ||
|
|
||
| $url = $request->headers->get('Referer', '/'); | ||
|
|
||
| if ($this->defaultRoute) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once the router property is nullable, you need to check if its set here as well |
||
| $redirect = $this->router->generate($this->defaultRoute); | ||
| } else { | ||
| $redirect = '/'; | ||
| } | ||
|
|
||
| $url = $request->headers->get('Referer', $redirect); | ||
|
|
||
| $response = new RedirectResponse($url); | ||
|
|
||
| if (!empty($this->cookieOptions)) { | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also make the
$routerparameter nullable to maintain BC?