function GotoAction::execute
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Action/Plugin/Action/GotoAction.php \Drupal\Core\Action\Plugin\Action\GotoAction::execute()
- 10 core/lib/Drupal/Core/Action/Plugin/Action/GotoAction.php \Drupal\Core\Action\Plugin\Action\GotoAction::execute()
- 11.x core/lib/Drupal/Core/Action/Plugin/Action/GotoAction.php \Drupal\Core\Action\Plugin\Action\GotoAction::execute()
Overrides ExecutableInterface::execute
File
-
core/
lib/ Drupal/ Core/ Action/ Plugin/ Action/ GotoAction.php, line 73
Class
- GotoAction
- Redirects to a different URL.
Namespace
Drupal\Core\Action\Plugin\ActionCode
public function execute($object = NULL) {
$url = $this->configuration['url'];
// Leave external URLs unchanged, and assemble others as absolute URLs
// relative to the site's base URL.
if (!UrlHelper::isExternal($url)) {
$parts = UrlHelper::parse($url);
// @todo '<front>' is valid input for BC reasons, may be removed by
// https://www.drupal.org/node/2421941
if ($parts['path'] === '<front>') {
$parts['path'] = '';
}
$uri = 'base:' . $parts['path'];
$options = [
'query' => $parts['query'],
'fragment' => $parts['fragment'],
'absolute' => TRUE,
];
// Treat this as if it's user input of a path relative to the site's
// base URL.
$url = $this->unroutedUrlAssembler
->assemble($uri, $options);
}
$response = new RedirectResponse($url);
$listener = function ($event) use ($response) {
$event->setResponse($response);
};
// Add the listener to the event dispatcher.
$this->dispatcher
->addListener(KernelEvents::RESPONSE, $listener);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.