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 #3151017: Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage() 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

Comments

catch created an issue. See original summary.

catch’s picture

Status: Postponed » Active
catch’s picture

Status: Active » Needs review
StatusFileSize
new1.4 KB

After #3151019: Only allow route names, deprecate support for route objects in UrlGenerator methods we don't need the logic at all, so can just remove the two calls to getRouteDebugMessage() in Drupal 10. However we'll need to move the logic inline if we want to trigger_error() from the methods..

catch’s picture

StatusFileSize
new2.64 KB

Adding the trigger_error().

Replacing getRouteDebugMessage() with a private @internal helper so we can avoid calling the original - and we can just remove the private message in Drupal 10 too.

The last submitted patch, 3: 3151017.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

catch’s picture

Issue tags: +@deprecated
StatusFileSize
new2.43 KB

Re-rolled.

catch’s picture

Title: [PP-1] Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage() » Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage()

Not postponed on anything now.

andypost’s picture

Status: Needs review » Needs work

NW for deprecation test and docs update

+++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
@@ -429,10 +429,28 @@ protected function getRoute($name) {
+   * @internal
...
+  private function getRouteStringIdentifier($name, array $parameters = []) {
+    if (is_scalar($name)) {
+      return $name;
...
+      return 'Route with pattern ' . $name->getPath();
...
+    return serialize($name);

needs @return in docblock

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new1.76 KB
new3.72 KB

Adding the deprecation testing and the @return.

andypost’s picture

StatusFileSize
new5.45 KB
new6.41 KB

Filed CR https://www.drupal.org/node/3172303 and updated patch with ref

Also updated other 2 places where unused methods implemented

andypost’s picture

StatusFileSize
new4.88 KB
new7.77 KB

As this methods undocumented now

- removed usage in testing code
- deprecated in remaining bubblable generator

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

At this time we will need a D10 patch and the deprecation to be 10.1 please

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new5.2 KB
new7.8 KB

updated for 10.1/11.0

andypost’s picture

StatusFileSize
new1 KB
new7.8 KB

fix indent for deprecation

smustgrave’s picture

Status: Needs review » Needs work

Close! Appears to be a CI issue.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.25 KB
new7.8 KB

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

smustgrave’s picture

Status: Needs review » Needs work
+   * @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!

ankithashetty’s picture

Status: Needs work » Needs review
StatusFileSize
new7.8 KB
new990 bytes

Addressed #22, thanks!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

#23 no longer applies.

andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new7.8 KB

one hunk context fix via #2574981: Fix grammar ("an URL" should be "a URL") and consistent use of URL (not "url" / "Url") in documentation only, part 1

-index bd3268d86d..b70af426fe 100644
+index b796efea45..eec14d17f9 100644
 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
 +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
 @@ -451,6 +451,18 @@ public function testBaseURLGeneration() {
@@ -187,5 +187,5 @@
 +  }
 +
    /**
-    * Tests that the 'scheme' route requirement is respected during url
+    * Tests that the 'scheme' route requirement is respected during URL
     * generation.
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Moving back thanks for the reroll!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 26: 3151017-26.patch, failed testing. View results

andypost’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated failure

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  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.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new506 bytes
new7.81 KB

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

alexpott’s picture

Status: Needs review » Needs work
+++ 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.

andypost’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new2.89 KB
new7.78 KB

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

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

andypost’s picture

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Points for #32 addressed

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed d532f6f 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:...
andypost’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

quietone’s picture

I published the change record.