Problem/Motivation

\Drupal\Core\Routing\Router::generate() is deprecated by we want people to use \Drupal\Core\Url object instead but this method is on aSymfony interface so we can't get rid of it.

This deprecation was added in #2810303: Reunite the router: One router to rule them all

Proposed resolution

Change to a warning? Exception?

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

catch’s picture

I think we would want to end up with an exception, but if we do that, should we redeprecate for Drupal 10? We'd need to update the message too to say it'll throw an exception as opposed to being removed.

andypost’s picture

Also there's 4 other implementations of interface except \Drupal\Core\Routing\Router::generate()
- \Drupal\Core\Routing\AccessAwareRouter::generate()
- \Drupal\Core\Routing\UrlGenerator::generate()
- \Drupal\Core\Render\MetadataBubblingUrlGenerator::generate()
- testing code \Drupal\help_test\SupernovaGenerator::generate() (throws exception)

Gábor Hojtsy’s picture

Status: Active » Needs review
FileSize
769 bytes

In discussion @catch proposed this:

I think we would be redeprecating for Drupal 10, but instead of saying it's removed, say it will start throwing an exception instead.

We cannot remove this as it is part of a Symfony interface. That said, it is not entirely fulfilling the interface contract if we are throwing an exception form it either, but that we can resolve in Drupal 9 to 10.

It was introduced deprecated outright in #2810303: Reunite the router: One router to rule them all before 8.3.0, that much I digged up. I don't think that is a good URL to include in the trigger_error() so I did not add that.

How does this look like?

andypost’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Routing/Router.php
@@ -331,7 +331,7 @@ public function getRouteCollection() {
+    @trigger_error(__NAMESPACE__ . '\Router::generate() is deprecated in drupal:8.3.0 and will throw an exception from drupal:10.0.0. Use the \Drupal\Core\Url object instead.', E_USER_DEPRECATED);

It could use __METHOD__ instead of __NAMESPACE__

And needs a test to catch this error

andypost’s picture

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. The change record at https://www.drupal.org/node/2820197 does not mention anything that this patch changes. I don't think it needs to explain what this specific method does.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed be4d1ec and pushed to 9.0.x. Thanks!

  • alexpott committed be4d1ec on 9.0.x
    Issue #3114869 by andypost, Gábor Hojtsy, catch: \Drupal\Core\Routing\...

Status: Fixed » Closed (fixed)

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