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.
#validate, #submit and ajax callbacks have already been improved to support method callbacks. The same thing should be done for #element_validate. This would be especially cool for field widgets.
#1802072: Ajax callbacks should be callbacks defined as function or class method
Change record for supporting FAPI #validate, #submit method callbacks: http://drupal.org/node/1734540
Comment | File | Size | Author |
---|---|---|---|
#9 | 1805688-9-element_validate.patch | 5.06 KB | fubhy |
#5 | 1805688-5-element_validate.patch | 4.67 KB | fubhy |
#1 | 1805688-1-element_validate.patch | 4.66 KB | fubhy |
Comments
Comment #1
fubhy CreditAttribution: fubhy commentedThe attached patch is the most simple solution to that. However, I am a little bit worried that, especially in case of field widgets, we might add multiple, identical object references to the form array. Not sure how we could easily solve that or if that is even a problem.
Comment #1.0
fubhy CreditAttribution: fubhy commentedAdding related issue references.
Comment #1.1
fubhy CreditAttribution: fubhy commentedAdding link to change record.
Comment #2
fubhy CreditAttribution: fubhy commentedFixing typo in title.
Comment #4
Stalski CreditAttribution: Stalski commentedThis should be
'#element_validate' => array(array($object, 'validateName')) since the callback function or array(object,method) is an array.
Comment #5
fubhy CreditAttribution: fubhy commentedWhoops... Of course :). Thanks @stalski.
Comment #6
Stalski CreditAttribution: Stalski commentedSetting the status to have the patch tested
Comment #7
Stalski CreditAttribution: Stalski commentedTested this and reviewed it. Straight forward patch imo
Comment #8
webchickThis looks good to me, and consistent with what we're doing elsewhere in form.inc, with one exception:
It's not kosher to declare classes inside module files. They need to be in PSR-0 files/folders.
While we're at it, can you please add PHPDoc for this class?
Comment #9
fubhy CreditAttribution: fubhy commentedSure.
Comment #10
Stalski CreditAttribution: Stalski commentedJust reviewed it. Again looking good.
I think this one is good to be committed.
Comment #11
webchickAwesome, thanks!
Committed and pushed to 8.x.
We'll need a change notice for this; can likely just be added to the existing FAPI one.
Comment #12
fubhy CreditAttribution: fubhy commentedDone.
http://drupal.org/node/1734540
Comment #13
swentel CreditAttribution: swentel commentedLooks good.
Comment #14
Stalski CreditAttribution: Stalski commentedPerfect fubhy.
Comment #15
Stalski CreditAttribution: Stalski commentedsubmissions at the same time
Comment #16
sunI'm unhappy that the existing test code was moved.
This means that we have a dedicated test for #element_validate using a class method now, but the dedicated test for a procedural function got lost.
The proper action would have been to add a second #element_validate entry for the class method and specifically assert that.
Comment #17
fubhy CreditAttribution: fubhy commentedThere are other tests that involve #element_validate and are not using method callbacks. What we are testing here is if #element_validate works. And we didn't change any #element_validate logic. We just changed is_function into is_callable. Actually I was unsure if it even makes sense to add a test for it at all. I mean.. We do not set up an array or an object in our tests to see if is_array() or is_object() works... Right? ;)
So... It doesn't matter what we do actually. And just in case - There are still other tests that use #element_validate with plain function callbacks.
Comment #18
fubhy CreditAttribution: fubhy commenteddoubleclick, sorry
Comment #20
xjmComment #20.0
xjmWoot, change records can be linked with node numbers :(