[CORE][Controller] Allow plugins to override redirect responses

This commit is contained in:
Diogo Peralta Cordeiro 2022-01-02 03:15:06 +00:00
parent 362fc6c7dd
commit f42e91d2bc
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
2 changed files with 6 additions and 3 deletions

View File

@ -132,6 +132,8 @@ abstract class Controller extends AbstractController implements EventSubscriberI
Event::handle('OverrideTemplate', [$this->vars, &$template]); // Allow plugins to replace the template used for anything
unset($this->vars['_template'], $response['_template']);
$redirect = $this->vars['_redirect'] ?? false;
$controller = $this->vars['controller'];
if (\is_array($controller)) {
$controller = $controller[0];
@ -156,7 +158,9 @@ abstract class Controller extends AbstractController implements EventSubscriberI
$event->setResponse(new JsonResponse($response));
break;
default: // html (assume if not specified)
if ($template !== null) {
if ($redirect !== false) {
$event->setResponse(new RedirectResponse($redirect));
} elseif (!\is_null($template)) {
$event->setResponse($this->render($template, $this->vars));
break;
} else {

View File

@ -36,7 +36,6 @@ use App\Core\DB\DB;
use function App\Core\I18n\_m;
use App\Core\Router\Router;
use App\Util\Exception\ClientException;
use App\Util\Exception\RedirectException;
use Component\Feed\Util\FeedController;
abstract class ActorController extends FeedController
@ -48,7 +47,7 @@ abstract class ActorController extends FeedController
{
$actor = DB::findOneBy('actor', ['id' => $id]);
if ($actor->getIsLocal()) {
throw new RedirectException(url: $actor->getUrl(Router::ABSOLUTE_PATH));
return ['_redirect' => $actor->getUrl(Router::ABSOLUTE_PATH), 'actor' => $actor];
}
if (empty($actor)) {
throw new ClientException(_m('No such actor.'), 404);