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

Breadcrumb

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

function RouteCompiler::getPathWithoutDefaults

Returns the path of the route, without placeholders with a default value.

When computing the path outline and fit, we want to skip default-value placeholders. If we didn't, the path would never match. Note that this only works for placeholders at the end of the path. Infix placeholders with default values don't make sense anyway, so that should not be a problem.

Parameters

\Symfony\Component\Routing\Route $route: The route to have the placeholders removed from.

Return value

string The path string, stripped of placeholders that have default values.

2 calls to RouteCompiler::getPathWithoutDefaults()
PathPluginBase::overrideAppliesPathAndMethod in core/modules/views/src/Plugin/views/display/PathPluginBase.php
Determines whether an override for the path and method should happen.
RouteCompiler::compile in core/lib/Drupal/Core/Routing/RouteCompiler.php
Compiles the current route instance.

File

core/lib/Drupal/Core/Routing/RouteCompiler.php, line 124

Class

RouteCompiler
Compiler to generate derived information from a Route necessary for matching.

Namespace

Drupal\Core\Routing

Code

public static function getPathWithoutDefaults(Route $route) {
    $path = $route->getPath();
    $defaults = $route->getDefaults();
    // Remove placeholders with default values from the outline, so that they
    // will still match.
    $remove = array_map(function ($a) {
        return '/{' . $a . '}';
    }, array_keys($defaults));
    $path = str_replace($remove, '', $path);
    return $path;
}

API Navigation

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