Verified Commit d532f6fd authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3151017 by andypost, catch, ankithashetty, smustgrave, alexpott:...

Issue #3151017 by andypost, catch, ankithashetty, smustgrave, alexpott: Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage()
parent 08177ee3
Loading
Loading
Loading
Loading
+28 −2
Changes for core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php: 28 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -110,16 +110,42 @@ public function generateFromRoute($name, $parameters = [], $options = [], $colle
  }

  /**
   * {@inheritdoc}
   * Checks if route name is a string or route object.
   *
   * @param string|\Symfony\Component\Routing\Route $name
   *   The route "name" which may also be an object or anything.
   *
   * @return bool
   *   TRUE if the passed in value a valid route, FALSE otherwise.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Only string
   *   route names are supported.
   *
   * @see https://www.drupal.org/node/3172303
   */
  public function supports($name) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Only string route names are supported. See https://www.drupal.org/node/3172303', E_USER_DEPRECATED);
    return $this->urlGenerator->supports($name);
  }

  /**
   * {@inheritdoc}
   * Gets either the route name or a string based on the route object.
   *
   * @param string|\Symfony\Component\Routing\Route $name
   *   The route "name" which may also be an object or anything.
   * @param array $parameters
   *   Route parameters array.
   *
   * @return string
   *   Either the route name, or a string that uniquely identifies the route.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use
   *   the route name instead.
   *
   * @see https://www.drupal.org/node/3172303
   */
  public function getRouteDebugMessage($name, array $parameters = []) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use the route name instead. See https://www.drupal.org/node/3172303', E_USER_DEPRECATED);
    return $this->urlGenerator->getRouteDebugMessage($name, $parameters);
  }

+55 −4
Changes for core/lib/Drupal/Core/Routing/UrlGenerator.php: 55 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ public function isStrictRequirements() {
   */
  public function getPathFromRoute($name, $parameters = []) {
    $route = $this->getRoute($name);
    $name = $this->getRouteDebugMessage($name);
    $name = $this->getRouteStringIdentifier($name);
    $this->processRoute($name, $route, $parameters);
    $path = $this->getInternalPathFromRoute($name, $route, $parameters);
    // Router-based paths may have a querystring on them but Drupal paths may
@@ -287,7 +287,7 @@ public function generateFromRoute($name, $parameters = [], $options = [], $colle
    $options += $route->getOption('default_url_options') ?: [];
    $options += ['prefix' => '', 'path_processing' => TRUE];

    $name = $this->getRouteDebugMessage($name);
    $name = $this->getRouteStringIdentifier($name);
    $this->processRoute($name, $route, $parameters, $generated_url);
    $path = $this->getInternalPathFromRoute($name, $route, $parameters, $options['query']);
    // Outbound path processors might need the route object for the path, e.g.
@@ -429,17 +429,68 @@ protected function getRoute($name) {
  }

  /**
   * {@inheritdoc}
   * Gets either the route name or a string based on the route object.
   *
   * @param string|\Symfony\Component\Routing\Route $name
   *   A string route name, or a serializable object.
   *
   * @return string
   *   Either the route name, or a string that uniquely identifies the route.
   *
   * @todo Remove in https://www.drupal.org/i/3151019
   *
   * @internal
   */
  private function getRouteStringIdentifier(string|SymfonyRoute $name): string {
    if (is_scalar($name)) {
      return $name;
    }

    if ($name instanceof SymfonyRoute) {
      return 'Route with pattern ' . $name->getPath();
    }

    return serialize($name);
  }

  /**
   * Checks if route name is a string or route object.
   *
   * @param string|\Symfony\Component\Routing\Route $name
   *   The route "name" which may also be an object or anything.
   *
   * @return bool
   *   TRUE if the passed in value a valid route, FALSE otherwise.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Only string
   *   route names are supported.
   *
   * @see https://www.drupal.org/node/3172303
   */
  public function supports($name) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Only string route names are supported. See https://www.drupal.org/node/3172303', E_USER_DEPRECATED);
    // Support a route object and any string as route name.
    return is_string($name) || $name instanceof SymfonyRoute;
  }

  /**
   * {@inheritdoc}
   * Gets either the route name or a string based on the route object.
   *
   * @param string|\Symfony\Component\Routing\Route $name
   *   The route "name" which may also be an object or anything.
   * @param array $parameters
   *   Route parameters array.
   *
   * @return string
   *   Either the route name, or a string that uniquely identifies the route.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use
   *   the route name instead.
   *
   * @see https://www.drupal.org/node/3172303
   */
  public function getRouteDebugMessage($name, array $parameters = []) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use the route name instead. See https://www.drupal.org/node/3172303', E_USER_DEPRECATED);
    if (is_scalar($name)) {
      return $name;
    }
+0 −14
Changes for core/modules/help/tests/modules/help_test/src/SupernovaGenerator.php: 0 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -45,18 +45,4 @@ public function generateFromRoute($name, $parameters = [], $options = [], $colle
    throw new \Exception();
  }

  /**
   * {@inheritdoc}
   */
  public function supports($name) {
    throw new \Exception();
  }

  /**
   * {@inheritdoc}
   */
  public function getRouteDebugMessage($name, array $parameters = []) {
    throw new \Exception();
  }

}
+12 −0
Changes for core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -451,6 +451,18 @@ public function testBaseURLGeneration() {
    $this->assertGenerateFromRoute('test_1', ['zoo' => 5], $options, 'http://www.example.com:8888/hello/world?zoo=5#top', (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT));
  }

  /**
   * Tests deprecated methods.
   *
   * @group legacy
   */
  public function testDeprecatedMethods() {
    $this->expectDeprecation('Drupal\Core\Routing\UrlGenerator::getRouteDebugMessage() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use the route name instead. See https://www.drupal.org/node/3172303');
    $this->assertSame('test', $this->generator->getRouteDebugMessage('test'));
    $this->expectDeprecation('Drupal\Core\Routing\UrlGenerator::supports() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Only string route names are supported. See https://www.drupal.org/node/3172303');
    $this->assertTrue($this->generator->supports('test'));
  }

  /**
   * Tests that the 'scheme' route requirement is respected during URL
   * generation.