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.
Just in passing I saw this earlier:
public function prepare(Request $request) {
parent::setData($this->ajaxRender($request));
return parent::prepare($request);
}
We don't usually directly call the parent like this for another method. There is no setData method on AjaxResponse so we're just calling JsonResponse::setData, which we can just do with $this->setData().
If there is a good reason for this, apologies in advance :)
Comment | File | Size | Author |
---|---|---|---|
d8.ajax-response-parent-call.patch | 546 bytes | damiankloip | |
Comments
Comment #1
fledev.com CreditAttribution: fledev.com commentedHi,
your point is right, the $this-> and parent:: are equal in that situation. You should not forget that while willing to extend the AjaxResponse's class with setData method would bring confusion into the prepare method.
While using the parent:: syntax, it is clearly defined that the extended - parent class method should be used there. The $this-> syntax is taking the parent if the actual object doesn't have it or the current object method.
Here's a small experiment which I've used to clear this:
Please process your issue regarding the solution or close it.
Comment #2
damiankloip CreditAttribution: damiankloip commentedI'm not really sure what your point is there :/
The fact that the parent class is used in that situation means you cannot use an overridden setData method. If it is not implemented on the class it will always inherit from the parent class. So $this->setData() will either get the current class or the inherited parent method. Isn't this just standard OOP?!
Comment #3
damiankloip CreditAttribution: damiankloip commented.
Comment #4
dawehnerIt's the same during runtime, but it's not the same in terms of expression of code. We call another function here, and not "extend" the function here.
This feels ready to fly.
Comment #5
catchCommitted/pushed to 8.x, thanks!