Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display helpful error message when redirect for source already exists #64

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Admin/RedirectAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public function configureViews(ViewCollection $viewCollection): void
new ToolbarAction('sulu_admin.add'),
new ToolbarAction('sulu_admin.delete'),
new ToolbarAction('sulu_admin.upload', [
'routeName' => 'sulu_redirect.import',
'route_name' => 'sulu_redirect.import',
'label' => 'sulu_redirect.import',
'multiple' => false,
'requestPropertyName' => 'redirectRoutes',
'request_property_name' => 'redirectRoutes',
'accept' => ['text/csv'],
]),
];
Expand Down
17 changes: 16 additions & 1 deletion Exception/RedirectRouteNotUniqueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

namespace Sulu\Bundle\RedirectBundle\Exception;

use Sulu\Component\Rest\Exception\TranslationErrorMessageExceptionInterface;

/**
* Redirect-route for given source already exists.
*/
class RedirectRouteNotUniqueException extends \Exception
class RedirectRouteNotUniqueException extends \Exception implements TranslationErrorMessageExceptionInterface
{
/**
* @var string
Expand Down Expand Up @@ -56,4 +58,17 @@ public function getSourceHost()
{
return $this->sourceHost;
}

public function getMessageTranslationKey(): string
{
return 'sulu_redirect.redirect_with_source_already_exist';
}

public function getMessageTranslationParameters(): array
{
return [
'%source%' => $this->source,
'%sourceHost%' => $this->sourceHost ?: '',
];
}
}
3 changes: 2 additions & 1 deletion Resources/translations/admin.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"sulu_redirect.source_host_info_text": "Leere Quelldomain verwenden um alle Domains zuzulassen.",
"sulu_redirect.target": "Ziel",
"sulu_redirect.status_code": "Status-Code",
"sulu_redirect.redirect_with_source_already_exist": "Es existiert bereits eine Umleitung mit der Quelle \"%source%\" und der Domain \"%sourceHost%\"",
"sulu_redirect.status_code.301": "301: Moved Permanently",
"sulu_redirect.status_code.302": "302: Moved Temporarily",
"sulu_redirect.status_code.410": "410: Gone",
Expand All @@ -17,6 +18,6 @@
"sulu_redirect.import.exceptions": "Fehlerhaft",
"sulu_redirect.exceptions.duplicated": "Zeile {lineNumber} in Datei \"{fileName}\" enthielt eine bereits importierte Quelle \"{source}\".",
"sulu_redirect.import.success": "{total} Umleitungen erfolgreich importiert.",
"sulu_redirect.errors.conflict": "TDie angegebene Quelle wurde bereits verwendet.",
"sulu_redirect.errors.conflict": "Die angegebene Quelle wurde bereits verwendet.",
"sulu_redirect.exceptions.target_empty": "Zeile {lineNumber} in Datei \"{fileName}\" enthielt ein leeres Ziel für die Quelle \"{source}\"."
}
1 change: 1 addition & 0 deletions Resources/translations/admin.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"sulu_redirect.source_host_info_text": "Use an empty source host to match all hosts.",
"sulu_redirect.target": "Target",
"sulu_redirect.status_code": "Status-Code",
"sulu_redirect.redirect_with_source_already_exist": "A redirect with the source \"%source%\" and host \"%sourceHost%\" already exists.",
"sulu_redirect.status_code.301": "301: Moved Permanently",
"sulu_redirect.status_code.302": "302: Moved Temporarily",
"sulu_redirect.status_code.410": "410: Gone",
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"require": {
"php": "^7.2 || ^8.0",
"sulu/sulu": "^2.2.4 || ^2.3@dev",
"sulu/sulu": "^2.2.5 || ^2.3@dev",
"ramsey/uuid": "^3.1 || ^4.0",
"symfony/dependency-injection": "^4.3 || ^5.0",
"symfony/config": "^4.3 || ^5.0",
Expand Down