forked from GNUsocial/gnu-social
[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
|
Event::handle('OverrideTemplate', [$this->vars, &$template]); // Allow plugins to replace the template used for anything
|
||||||
unset($this->vars['_template'], $response['_template']);
|
unset($this->vars['_template'], $response['_template']);
|
||||||
|
|
||||||
|
$redirect = $this->vars['_redirect'] ?? false;
|
||||||
|
|
||||||
$controller = $this->vars['controller'];
|
$controller = $this->vars['controller'];
|
||||||
if (\is_array($controller)) {
|
if (\is_array($controller)) {
|
||||||
$controller = $controller[0];
|
$controller = $controller[0];
|
||||||
@ -156,7 +158,9 @@ abstract class Controller extends AbstractController implements EventSubscriberI
|
|||||||
$event->setResponse(new JsonResponse($response));
|
$event->setResponse(new JsonResponse($response));
|
||||||
break;
|
break;
|
||||||
default: // html (assume if not specified)
|
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));
|
$event->setResponse($this->render($template, $this->vars));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
@ -36,7 +36,6 @@ use App\Core\DB\DB;
|
|||||||
use function App\Core\I18n\_m;
|
use function App\Core\I18n\_m;
|
||||||
use App\Core\Router\Router;
|
use App\Core\Router\Router;
|
||||||
use App\Util\Exception\ClientException;
|
use App\Util\Exception\ClientException;
|
||||||
use App\Util\Exception\RedirectException;
|
|
||||||
use Component\Feed\Util\FeedController;
|
use Component\Feed\Util\FeedController;
|
||||||
|
|
||||||
abstract class ActorController extends FeedController
|
abstract class ActorController extends FeedController
|
||||||
@ -48,7 +47,7 @@ abstract class ActorController extends FeedController
|
|||||||
{
|
{
|
||||||
$actor = DB::findOneBy('actor', ['id' => $id]);
|
$actor = DB::findOneBy('actor', ['id' => $id]);
|
||||||
if ($actor->getIsLocal()) {
|
if ($actor->getIsLocal()) {
|
||||||
throw new RedirectException(url: $actor->getUrl(Router::ABSOLUTE_PATH));
|
return ['_redirect' => $actor->getUrl(Router::ABSOLUTE_PATH), 'actor' => $actor];
|
||||||
}
|
}
|
||||||
if (empty($actor)) {
|
if (empty($actor)) {
|
||||||
throw new ClientException(_m('No such actor.'), 404);
|
throw new ClientException(_m('No such actor.'), 404);
|
||||||
|
Loading…
Reference in New Issue
Block a user