Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage()

Created on 11 June 2020, over 4 years ago
Updated 8 September 2023, about 1 year ago

Problem/Motivation

Following #2917331: Decouple from Symfony CMF the methods UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage() no longer need to be public.

We can deprecate those methods for removal in Drupal 11, and move the logic inline into the methods on UrlGenerator that call them.

Proposed resolution

Deprecate this methods and do further clean-up in 📌 Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage() Fixed as route object has no idea about its name in collection

Remaining tasks

User interface changes

API changes

Two new deprecations, although of methods that should never get called usually.

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

10.1

Component
Routing 

Last updated 3 days ago

Created by

🇬🇧United Kingdom catch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs review almost 2 years ago
  • Status changed to Needs work almost 2 years ago
  • Status changed to Needs review almost 2 years ago
  • 🇫🇷France andypost

    As I see the $parameters argument is not used and looking how $name argument is passed I set it type to expected

    string|\Symfony\Component\Routing\Route
  • Status changed to Needs work almost 2 years ago
  • 🇺🇸United States smustgrave
    +   * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
    +   *   the route name instead.
    

    Think that's the last little bit and I'm good to mark it!

  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India ankithashetty Karnataka, India

    Addressed #22, thanks!

  • Status changed to RTBC almost 2 years ago
  • 🇺🇸United States smustgrave

    Thanks!

  • Status changed to Needs work almost 2 years ago
  • 🇬🇧United Kingdom catch

    #23 no longer applies.

  • Status changed to Needs review almost 2 years ago
  • 🇫🇷France andypost

    one hunk fix

  • Status changed to RTBC almost 2 years ago
  • 🇺🇸United States smustgrave

    Moving back thanks for the reroll!

  • 🇫🇷France andypost

    Unrelated failure

  • Status changed to Needs work almost 2 years ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍
    1. Nice to get this cleaned up!
    2. +++ b/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php
      @@ -110,16 +110,42 @@ public function generateFromRoute($name, $parameters = [], $options = [], $colle
      +    @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);
      ...
      +    @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);
      

      I always find this a bit tricky - given the urlGenerator method triggers a deprecation is adding the deprecation here necessary. Sure to the docs - but doubling up on every deprecation message can be noisy. Not sure.

    3. +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
      @@ -429,17 +429,17 @@ protected function getRoute($name) {
      -  public function getRouteDebugMessage($name, array $parameters = []) {
      +  private function getRouteStringIdentifier($name) {
      

      Let's add return and parameter typehinting.

    4. +++ b/core/modules/help/tests/modules/help_test/src/SupernovaGenerator.php
      @@ -45,18 +45,4 @@ public function generateFromRoute($name, $parameters = [], $options = [], $colle
      -  /**
      -   * {@inheritdoc}
      -   */
      -  public function supports($name) {
      -    throw new \Exception();
      -  }
      -
      -  /**
      -   * {@inheritdoc}
      -   */
      -  public function getRouteDebugMessage($name, array $parameters = []) {
      -    throw new \Exception();
      -  }
      

      Given this is test code I think this is fine.

  • Status changed to Needs review almost 2 years ago
  • 🇫🇷France andypost

    Fix #30.2 and about 1) - I see no usage so no reason to throttle warnings

  • Status changed to Needs work almost 2 years ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍
    +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
    @@ -429,17 +429,17 @@ protected function getRoute($name) {
    -  public function getRouteDebugMessage($name, array $parameters = []) {
    +  private function getRouteStringIdentifier($name): string {
    
    @@ -451,4 +451,45 @@ public function getRouteDebugMessage($name, array $parameters = []) {
    +  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->getRouteStringIdentifier($name);
    +  }
    

    string|SymfonyRoute $name can typehint the param too.

    But that also means we should leave the implementation of the old getRouteDebugMessage() alone - which is normally for the best anyway.

  • Status changed to Needs review almost 2 years ago
  • 🇫🇷France andypost

    I think new private method will be removed in 📌 Only allow route names, deprecate support for route objects in UrlGenerator methods Fixed

    I mean getRouteStringIdentifier() is a full copy of getRouteDebugMessage() (which we can't type hint except doc-block as existing) so I copied code and added todo with link

    updated IS

  • Status changed to RTBC almost 2 years ago
  • 🇺🇸United States smustgrave

    Points for #32 addressed

  • Status changed to Fixed almost 2 years ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Committed 42f687a and pushed to 10.1.x. Thanks!

    diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
    index eec14d17f92..54d169f76ae 100644
    --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
    +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
    @@ -458,9 +458,9 @@ public function testBaseURLGeneration() {
        */
       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->generator->getRouteDebugMessage('test');
    +    $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->generator->supports('test');
    +    $this->assertTrue($this->generator->supports('test'));
       }
     
       /**
    

    Added test coverage of the deprecated method return value.

    • alexpott committed d532f6fd on 10.1.x
      Issue #3151017 by andypost, catch, ankithashetty, smustgrave, alexpott:...
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed about 1 year ago
  • 🇳🇿New Zealand quietone

    I published the change record.

Production build 0.71.5 2024