[CORE][Controller] Allow plugins to override redirect responses
This commit is contained in:
parent
362fc6c7dd
commit
f42e91d2bc
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user