Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. GotoAction.php

function GotoAction::execute

Overrides ExecutableInterface::execute

File

core/lib/Drupal/Core/Action/Plugin/Action/GotoAction.php, line 74

Class

GotoAction
Redirects to a different URL.

Namespace

Drupal\Core\Action\Plugin\Action

Code

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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal