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.
The onView, onHtml, onJson etc methods of the ViewSubscriber class all take a GetResponseEvent object as their only parameter, on which most proceed to call the getControllerResult() method. However, the GetResponseEvent class does not have such a method. What actually gets passed is a GetResponseForControllerResultEvent object so I'm pretty sure that's what ought to be in the method signature.
Patch forthcoming...
Comment | File | Size | Author |
---|---|---|---|
#1 | 1643702.viewsubscriber-method-signature.patch | 2.9 KB | katbailey |
Comments
Comment #1
katbailey CreditAttribution: katbailey commentedComment #2
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedYep, good catch, thanks! I'd also say this isn't really minor, but rather misleading enough for normal ;)
Comment #3
chx CreditAttribution: chx commentedHrm, how can tests pass then? Oh, I see class GetResponseForControllerResultEvent extends GetResponseEvent so the signature didn't cause an immediate fatal. Do we need tests for this?
Comment #4
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedWell ... it is barely possible to test this then, no?
Comment #5
katbailey CreditAttribution: katbailey commentedI don't see how we could write a test for this - the onView method will always get a GetResponseForControllerResultEvent passed in because it's subscribed to the kernel.view event and that's the class of event that gets thrown. So calling the getControllerResult() method on the object will never cause a problem.
It's just that the signature is wrong.
Comment #6
chx CreditAttribution: chx commentedOK then.
Comment #7
Dries CreditAttribution: Dries commentedGood catch. Committed to 8.x.