Problem/Motivation
To quote \Drupal\Core\Render\Element\MachineName:
exists: A callable to invoke for checking whether a submitted machine name value already exists. The submitted value is passed as an argument. In most cases, an existing API or menu argument loader function can be re-used. The callback is only invoked if the submitted value differs from the element's #default_value.
This doesn't document the remaining two parameters used in the callback:
call_user_func($function, $element['#value'], $element, $form_state)
This recently came up where some code was assuming parameter 2 was the full form, and not just the form element, and the only way to figure it out was to dive into validateMachineName()
method.
Proposed resolution
Describe the additional parameters in the documentation.
Remaining tasks
Commit the patch
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#27 | document_parameters-2173831-27.patch | 886 bytes | vegantriathlete |
#27 | interdiff.21-27.txt | 730 bytes | vegantriathlete |
#21 | document_parameters-2713831-20.patch | 891 bytes | vegantriathlete |
#21 | interdiff.19-6.txt | 693 bytes | vegantriathlete |
#19 | document_parameters-2713831-19.patch | 891 bytes | joshi.rohit100 |
Comments
Comment #2
jhodgdonThanks! I think this would be a good Novice project.
Comment #3
kellyimagined CreditAttribution: kellyimagined commentedWe will begin looking at this issue
Comment #4
vegantriathleteWe will be adding a proper issue summary and we will roll a patch for the docblock.
Comment #5
marlatt CreditAttribution: marlatt commentedComment #6
lisa.ugray CreditAttribution: lisa.ugray at University of Ottawa commentedAdded missing callback parameters to the documentation.
Comment #7
selfuntitled CreditAttribution: selfuntitled commentedComment #8
kellyimagined CreditAttribution: kellyimagined commentedComment #9
lisa.ugray CreditAttribution: lisa.ugray at University of Ottawa commentedComment #10
lisa.ugray CreditAttribution: lisa.ugray at University of Ottawa commentedComment #11
munizjor CreditAttribution: munizjor commentedIssue tag has been reverted back to 8.1, but the patch will be applied to 8.2. Will review after lunch.
Comment #12
soulsesa CreditAttribution: soulsesa commentedPreviously, only the submitted value was documented. Now the submitted value, form element array and form state have been documented.
Comment #13
akalata CreditAttribution: akalata commentedI'm not sure that this issue is RTBC yet. Are these arguments being passed as an array? If so, do they match up with expected variables or key values?
Comment #14
lisa.ugray CreditAttribution: lisa.ugray at University of Ottawa commentedThe callable is being passed in. These are the arguments that will be passed to the callable.
Comment #15
lisa.ugray CreditAttribution: lisa.ugray at University of Ottawa commentedComment #16
vegantriathleteThe point of the patch was to add documentation about the parameters that are being passed via call_user_func(). As stated in the issue summary:
is the section of the code we are documenting. The original docblock mentioned only the submitted value parameter. It did not mention the other two parameters. The attached patch has included the mention of the other two parameters.
Comment #17
vegantriathleteComment #18
alexpottThis is not an array - it is an object that implements FormStateInterface
Comment #19
joshi.rohit100Comment #21
vegantriathlete@alexpott Thanks for the clarification!
@joshi.rohit100
Thanks for submitting a new patch! Here are a couple of points to consider:
Comment #22
vegantriathleteComment #25
lisa.ugray CreditAttribution: lisa.ugray at University of Ottawa commentedTest failure was due to the branch, not the patch, as shown by retesting. Thanks @alexpott for that catch - I'm too used to D7. The latest patch looks good to me.
Comment #26
jhodgdonLooking pretty good...
... but I think this is slightly confusing. See issue summary -- this issue was filed because of confusion between the form and the element. How about leaving the word "form" out here?
Comment #27
vegantriathleteComment #29
jhodgdonTest failure seems to be unrelated. The patch looks good to me. Thanks!
Comment #30
deviantintegral CreditAttribution: deviantintegral at Lullabot commentedLooks good to me as well. Thanks!
Comment #33
webchickCommitted and pushed to 8.2.x and cherry-picked to 8.1.x. Thanks!
Great to see the team work going on here. :)