Problem/Motivation

Following #2917331: Decouple from Symfony CMF we can simplify the implementation of, and reduce the API surface of, methods in UrlGenerator that accept both a route name and route object.

Examples:

UrlGenerator::getPathFromRoute()

UrlGenerator::generateFromRoute()

(also supporting protected methods)

In Drupal 10, this would also allow us to string typehint for those methods too.

Proposed resolution

Trigger a deprecation message when a route object is passed in.

Remaining tasks

While there's not a strict dependency in either direction, this issue is closely linked to #3151017: Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage().

User interface changes

API changes

Data model changes

Release notes snippet

Comments

catch created an issue. See original summary.

catch’s picture

catch’s picture

Issue summary: View changes
andypost’s picture

catch’s picture

Status: Active » Needs review
StatusFileSize
new1.65 KB

Needs deprecation testing adding, but also want to see if any existing test coverage fails first.

catch’s picture

StatusFileSize
new1.65 KB

Status: Needs review » Needs work

The last submitted patch, 6: 3151019-6.patch, failed testing. View results

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new1.68 KB

Backtraces on the test failures aren't helpful, let's try this.

Status: Needs review » Needs work

The last submitted patch, 8: 3151019-7.patch, failed testing. View results

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new1.05 KB
new2.69 KB

Comment pager is passing in the route object, this should fix at least some of the test failures.

Status: Needs review » Needs work

The last submitted patch, 10: 3151019-10.patch, failed testing. View results

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new634 bytes
new3.31 KB

config_translation is relying on ::setRedirect() accepting a route object implictly.

catch’s picture

StatusFileSize
new3.09 KB
new6.14 KB

With deprecation testing now.

catch’s picture

andypost’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
@@ -430,7 +438,11 @@ protected function getRoute($name) {
+   * @deprecated in drupal:9.1.0 and is removed in drupal:10.0.0

@@ -438,7 +450,11 @@ public function supports($name) {
+   * @deprecated in drupal:9.1.0 and is removed in drupal:10.0.0.

it needs @see to CR and explanation with replacement, or may use follow-up

catch’s picture

We should remove the ::supports and ::getRouteDebugMessage() hunks from this patch and do them in #3151017: Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage().

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new909 bytes
new5.96 KB
andypost’s picture

  1. +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
    @@ -417,6 +423,8 @@ protected function processRoute($name, SymfonyRoute $route, array &$parameters,
    +   * @internal
    +   *
        * @see \Drupal\Core\Routing\RouteProviderInterface
    ...
       protected function getRoute($name) {
    

    This method overriden only once in \Drupal\Core\Routing\NullGenerator::getRoute() and implementation sounds for legacy support, could use follow-up to clean-up for d10

  2. +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
    @@ -430,7 +438,7 @@ protected function getRoute($name) {
    -   * {@inheritdoc}
    +   * Checks if route name is a string or route object.
    
    @@ -438,7 +446,7 @@ public function supports($name) {
    -   * {@inheritdoc}
    +   * Gets either the route name or a string based on the route object.
    

    not sure this change needed, as there's 2 more classes now implements this methods and have broken "inheritdoc" there too, see #3151017-10: Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage()

    - \Drupal\Core\Render\MetadataBubblingUrlGenerator::supports
    - \Drupal\help_test\SupernovaGenerator::supports

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.

wim leers’s picture

+++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
@@ -127,6 +127,9 @@ public function isStrictRequirements() {
   public function getPathFromRoute($name, $parameters = []) {
+    if (!is_string($name)) {
+      @trigger_error('Passing a route object to ' . __METHOD__ . ' is deprecated in drupal:9.1.0 and will not be supported in drupal:10.0.0. Pass the route name instead. See https://www.drupal.org/node/3172280', E_USER_DEPRECATED);
+    }

+100 for this per #2491981: There are too many ways to generate URLs and links!

Can we still land this? 🤞🤓

andypost’s picture

StatusFileSize
new3.57 KB
new5.97 KB

reroll for 9.2

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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

catch’s picture

#3151017: Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage() is RTBC except for a re-roll, might be worth waiting on that just to avoid any potential conflicts.

I think this patch is in good shape except we need to update the deprecation messages to drupal:10.1.0 for removal in drupal:11.0.0.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new3.44 KB
new5.98 KB

re-roll for 10.1 and there's only context conflict with #3151017: Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage() so better to commit it

+++ b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php
@@ -178,7 +178,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
-            $build['pager']['#route_name'] = $this->routeMatch->getRouteObject();
+            $build['pager']['#route_name'] = $this->routeMatch->getRouteName();

+++ b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php
@@ -219,7 +219,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
-      $this->mapper->getOverviewRoute(),
+      $this->mapper->getOverviewRouteName(),

this 2 places anyway needs fix

andypost’s picture

Status: Needs review » Needs work

It needs follow-up to remove deprecated methods in D11 and new method UrlGenerator::getRouteStringIdentifier() added in related issue #3151017: Deprecate UrlGenerator::supports() and UrlGenerator::getRouteDebugMessage()

andypost’s picture

andypost’s picture

Status: Postponed » Needs review
StatusFileSize
new4.19 KB
new5.75 KB

blocker commited, here's re-roll and polishing of test and place to throw deprecation

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new85 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

nod_’s picture

Status: Needs work » Needs review

Umm, issue with the bot

andypost’s picture

Somehow re-testing aborted, queued PHP 8.2 meantime but curious if there's some performance regression happened

andypost’s picture

tests are passed, I see no difference in time - the same 1h for run

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Deprecation message is up to date,
Change record is simple and clear.
Has test coverage for deprecation.
Code looks good to me.

  • longwave committed 39665920 on 10.1.x
    Issue #3151019 by catch, andypost: Only allow route names, deprecate...
longwave’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 10.1.x, thanks!

Status: Fixed » Closed (fixed)

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