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.
If you define a Route in a *.routing.yaml file like this the options don't make it to the Route object:
router_test_1:
pattern: '/router_test/test1'
defaults:
_controller: '\Drupal\router_test\TestControllers::test1'
requirements:
_access: 'TRUE'
options:
foo: 'bar'
This is because Drupal\Core\Routing\RouteBuilder isn't passing the options to the Route's constructor.
Patch follows.
Follow-ups:
- #1859684: Expand routeBuilder unit test
Comment | File | Size | Author |
---|---|---|---|
#14 | 1855204-routebuilder.patch | 876 bytes | effulgentsia |
#5 | 1855204-routebuilder.patch | 4.6 KB | g.oechsler |
#4 | 1855204-routebuilder.patch | 4.6 KB | g.oechsler |
#1 | 1855204-routebuilder.patch | 876 bytes | g.oechsler |
Comments
Comment #1
g.oechsler CreditAttribution: g.oechsler commentedComment #2
Crell CreditAttribution: Crell commentedI can't see how the bot would choke on this, and it's a legit bug fix. (The bot can disagree with me if it likes.)
Comment #3
klausiNeeds a test case.
Comment #4
g.oechsler CreditAttribution: g.oechsler commentedHere it is with a test for this.
Comment #5
g.oechsler CreditAttribution: g.oechsler commenteds/self::/$this->/
Comment #6
Crell CreditAttribution: Crell commentedThat's even better!
Comment #7
Lars Toomre CreditAttribution: Lars Toomre commentedMissing @param and @return directives in this docblock.
Comment #8
webchickCorrect. Lars, can you please re-roll the patch with that added?
Also, it was my understanding we can't define multiple classes per file? What's up with that?
Comment #9
g.oechsler CreditAttribution: g.oechsler commentedWhat about http://drupal.org/coding-standards/docs#functions ?
Also I could not find a rule that says we can't define multiple classes per file. Could you please point me to it?
After thinking of this I come to the conclusion that a test for this is odd anyway.
Look what we want to do:
Now #5 is a 4.6 KB patch. If we really need to split out the dummy classes (and certainly properly document all the noop methods) it will be even bigger. For me the "signal to noise ratio" of this would be below my personal feel-good threshold.
Anyway, the bug this is patching was introduced in #1801570 DX: Replace hook_route_info() with YAML files and RouteBuildEvent which came away without a test for RouteBuilder. So in facts it's not this issue that needs testing, it's #1801570.
I think #1 should be commited and we should file a follow up of #1801570 demanding a test case.
Comment #10
aspilicious CreditAttribution: aspilicious commentedFirst of all it should be "CreateS". And we always describe params. It surprises me that line is in the docs manual.
About mutliple classes in one file. I'm surprised that even works. When you define multiple classes in a single file the autoloader can't load the classes. Maybe it works here because you're calling the classes from the same file. If some other tests want to use the same class they can't because there is no way it ever can load the class.
Last thingie, we are alwyas trying to replicate real drupal situations in tests. So why are you not using a config file and load it like we do in other tests?
Patch size isn't a problem.
Comment #11
g.oechsler CreditAttribution: g.oechsler commentedI think it is kind of funny we're discussing a method and some dummy classes for a test that wouldn't exist if the feature this patch is fixing had proper tests in the first place.
So as stated before what's missing is the tests for #1801570, which I believe is out of scope of this bugfix.
I still think #1 is a sufficient patch for the bug and needs review. Please ignore patch #5.
Comment #12
Crell CreditAttribution: Crell commentedHuh. I didn't even realize that the patch above was adding the extra test classes in the same file. That's my error.
We are following strict PSR-0 class loading, which does mean one class per file, period. The autoloader can't handle it otherwise.
g.oechsler: Welcome to core development. :-)
I'm personally comfortable with committing #1 as if. If we insist on a full on test suite, that can be a follow up unless someone pounces on this quickly, because that bug fix is a blocker for #1798214: Upcast request arguments/attributes to full objects. (Insert someone telling me "that's why we need unit tests" here.) #11's point is still valid.
Comment #13
effulgentsia CreditAttribution: effulgentsia commentedI agree that if we commit anything here, it should be #1 and no more. But I don't understand why we need to commit this separately rather than as part of some use case that needs it, like #1798214: Upcast request arguments/attributes to full objects. When we get a use case that needs it in, the proper test for it would be a functional test of that use case in Drupal\system\Tests\Routing\RouterTest.
I'd like to point out that http://symfony.com/doc/2.0/book/routing.html contains no mention of what $options is for. http://symfony.com/legacy/doc/reference/1_4/en/10-Routing#chapter_10_sfo... documents it a little bit in relation to argument upcasting, but that's a legacy Symfony version. Is options useful for anything other than upcasting? If not, then I'm even more confused why this is a separate issue from #1798214: Upcast request arguments/attributes to full objects.
Comment #14
effulgentsia CreditAttribution: effulgentsia commentedActually, I might have been too harsh in #13. Since we're using Symfony Route objects, and Symfony Route objects provide for a $options property, then even without any use case, Drupal's RouteBuilder should allow for it to be used. I do think we'll want functional tests for integrating it with argument upcasting, but that's a job for #1798214: Upcast request arguments/attributes to full objects. Separately, RouteBuilder unit tests would be nice, but what we need to unit test is the rebuild() method, not the getRouteFromInfo() method, which should either be inlined or protected. But, RouteBuilder already states that it can't be unit tested without #1331486: Move module_invoke_*() and friends to an Extensions class, so that shouldn't hold up this enhancement.
Therefore, reuploading #1 and RTBC'ing it.
Comment #16
effulgentsia CreditAttribution: effulgentsia commented#14: 1855204-routebuilder.patch queued for re-testing.
Comment #17
effulgentsia CreditAttribution: effulgentsia commentedAnd now that bot passed the retest, back to rtbc.
Comment #18
effulgentsia CreditAttribution: effulgentsia commentedI opened #1859684: Expand routeBuilder unit test and added it as a follow-up to this issue's summary.
Comment #19
webchickI was going to knock this back to needs work for tests, but #14 explains why not, and that they'll be added elsewhere. Talking to Alex, he decided to create a major task to unit test this in a more holistic way (although it's currently postponed on #1331486: Move module_invoke_*() and friends to an Extensions class).
Committed and pushed to 8.x. Thanks!
Comment #20.0
(not verified) CreditAttribution: commentedUpdated issue summary.