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

Breadcrumb

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

function PathChangedHelper::__construct

Constructs a PathChangedHelper object.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: A route match object, used for the route name and the parameters.

\Symfony\Component\HttpFoundation\Request $request: A request object, used for the query parameters.

Throws

\InvalidArgumentException The route name from $route_match must end with ".bc".

File

core/lib/Drupal/Core/Routing/PathChangedHelper.php, line 63

Class

PathChangedHelper
Provides helper functions for handling path changes.

Namespace

Drupal\Core\Routing

Code

public function __construct(RouteMatchInterface $route_match, Request $request) {
    $bc_route_name = $route_match->getRouteName();
    if (!str_ends_with($bc_route_name, '.bc')) {
        throw new \InvalidArgumentException(__CLASS__ . ' expects a route name that ends with ".bc".');
    }
    // Strip '.bc' from the end of the route name.
    $route_name = substr($bc_route_name, 0, -3);
    $args = $route_match->getRawParameters()
        ->all();
    $options = [
        'absolute' => TRUE,
        'query' => array_diff_key($request->query
            ->all(), [
            'destination' => '',
        ]),
    ];
    $this->newUrl = Url::fromRoute($route_name, $args, $options);
    $this->oldUrl = Url::fromRoute($bc_route_name, $args, $options);
}

API Navigation

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