Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Since we now have #2047619: Add a link generator service for route-based links , we should provide a short-cut that's nearly as easy for developers to use as l() and url() for generating a link or url from a route and parameters.
Comment | File | Size | Author |
---|---|---|---|
#12 | drupal-url-2078285-12.patch | 1.06 KB | tim.plunkett |
#7 | drupal-l-2078285-7.patch | 9.66 KB | pwolanin |
#7 | 2078285-5-7.increment.txt | 3.74 KB | pwolanin |
#5 | 2078285-4-5.increment.txt | 5.51 KB | pwolanin |
#5 | drupal-l-2078285-5.patch | 9.37 KB | pwolanin |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedComment #2
pwolanin CreditAttribution: pwolanin commentedclosed as duplicate: #2051813: Reuse the link generator to provide a Drupal::link() function
Comment #3
pwolanin CreditAttribution: pwolanin commentedmissing text for the link...
Comment #4
dawehner+++ b/core/lib/Drupal.php
@@ -381,6 +381,17 @@ public static function urlGenerator() {
+ public static function url($route_name, $rotue_parameters = array(), $options = array()) {
+ return static::$container->get('url_generator')->generateFromRoute($route_name, $route_parameters, $options);
@@ -390,6 +401,17 @@ public static function linkGenerator() {
+ public static function l($route_name, $rotue_parameters = array(), $options = array()) {
+ return static::$container->get('link_generator')->generate($route_name, $route_parameters, $options);
I tried to find funny images of rotue but I couldn't find one :(
Let's do the url() bits into #2073813: Add a UrlGenerator helper to FormBase and ControllerBase and concentrate on the link generator here.
Yes this unit test is kind of pointless, but nevertheless I want to show people that they should use unit tests where possible.
Comment #5
pwolanin CreditAttribution: pwolanin commentedSince Drupal::url() doesn't' seem to be in the FormBase patch, adding it back here plus more doxygen and oxygen fixes.
I thin a DX question here is whether we want to catch some or all of the possible exceptions - e.g. in the way url() does if the generator is not initialized.
Comment #6
dawehnerPlease copy the docs from the other issue, they are alligned properly.
Comment #7
pwolanin CreditAttribution: pwolanin commented@dawehner - ha, indeed - when I looked at your other patch I figured we'd need to copy that version to here.
Comment #8
dawehnerWell we don't test the url() methods but I don't really care.
Comment #9
webchickI'm guessing
return static::$container->get('url_generator')->generateFromRoute($route_name, $route_parameters, $options);
is already tested elsewhere. If so, I don't see an overly compelling reason to test a wrapper function. Especially only one of them and not both.That fills my soul with happiness tho.
Comment #10
webchickActually, I can just commit it without that hunk.
Committed and pushed to 8.x. Thanks!
Comment #11
pwolanin CreditAttribution: pwolanin commentedupdated these 2 change notices:
https://drupal.org/node/2078263
https://drupal.org/node/2072005
Comment #12
tim.plunkettThis is broken.
Comment #13
tim.plunkettComment #14
brianV CreditAttribution: brianV commentedRTBC, perfect
Comment #15
alexpottCommitted 21eaf37 and pushed to 8.x. Thanks!
Comment #16
damiankloip CreditAttribution: damiankloip commentedIn light of that, I opened #2089787: Unit test the \Drupal class.