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.
API page: http://api.drupal.org/api/drupal/core%21includes%21form.inc/function/dru...
The documentation page, right before "Related topics," shows the following text:
would be called via
drupal_form_submit()
as follows:$form_state['values'] = $my_form_values; $form_state['build_info']['args'] = array(&$object); drupal_form_submit('mymodule_form', $form_state);
For example:
After the last line, I guess there should be an example, but the page doesn't show any example. It seems the example has been given, and the page should contain the following text.
would be called via
drupal_form_submit()
as follows, for example:$form_state['values'] = $my_form_values; $form_state['build_info']['args'] = array(&$object); drupal_form_submit('mymodule_form', $form_state);
Comment | File | Size | Author |
---|---|---|---|
#36 | 1650198-36.patch | 3.01 KB | Nikhil_110 |
#35 | 1650198-nr-bot.txt | 162 bytes | needs-review-queue-bot |
#30 | move_example_code-1650198-30.patch | 2.36 KB | manishsaharan |
#25 | move-example-code-1650198-25.patch | 2.2 KB | apaderno |
#21 | move-example-code-1650198-21.patch | 2.19 KB | apaderno |
Comments
Comment #1
longwaveThe missing example appears to be the "register a new user" code block, which instead appears before Parameters.
Comment #2
apadernoIt seems not. The topic in the last snippet shown in that page is "passing arguments that need to be passed by reference to the menu callback." This is the context.
Comment #3
apadernoEffectively, it seems a problem with how the part about the parameters is extracted from the comment.
The "For example:" line is considered part of the @param block, while it is not. To resolve the issue, it should be enough to move the example code before the @param block.
Comment #4
apadernoThis is a first tentative to resolve the issue.
Comment #5
apadernoAs alternative, the example code is simply moved.
Comment #6
jhodgdonPlease do not put the "do not test" suffix on patches that you think might need to be committed to core. The maintainers (speaking for myself anyway) who make commits like to have all patches tested, just to make sure there isn't a syntax error that has crept into the patch. Only use "do not test" if you are attaching an invalid patch (such as a 7.x or 6.x patch on an 8.x issue).
Anyway, that aside... The patch in #5 -- I don't like it, because it just seems to put some code into the documentation with no explanation.
The patch in #4 is also not quite right -- there shouldn't be a blank line between "For example..." and the @code that provides that example. Instead, that "for example" line should end in : and the blank line should be removed.
But... I'm confused about this anyway. There is already one example in the documentation. Why do we even need this second example? Choose one or the other, whichever provides the best example.
Comment #7
apadernoIt's not a different example: It's the same example that is moved to solve an issue with the rendering.
The comment for that function is the following one.
It is rendered as in the following screenshots.
Using "For example:" before the example doesn't seem to make sense, as that phrase would follow the following sentence:
drupal_static() uses just "Example:", before the examples.
Looking at the comment used for that function, this is what it contains.
The examples are before the first @param directive.
Comment #8
apadernoComment #9
jhodgdonWhat I was trying to say is that there is one example:
And then there is this other example:
I do not understand why we need both. It doesn't seem to me that the second example adds much of anything to the discussion, and actually I'm not sure the first one does either. We have the "N functions call this one" to provide examples anyway -- normally we don't put them in the function's doc block?
Comment #10
apadernoThe first example you are referring is about passing arguments that need to be passed by reference; it is not how the function is normally used, and I think it's worth pointing out how the function should be called in that case.
The second example is showing code that is not used in any of the functions calling
drupal_form_submit()
uses, and that code has a specific purpose.Most of the Drupal functions are called from Drupal itself. IMO, that doesn't mean the documentation of a function should not evidence something that is relevant for calling the function. Differently, the documentation for
drupal_static()
should not report the advanceddrupal_static()
pattern, nor suggest using the PHP magic__FUNCTION__
constant, as that information can be obtained from Drupal code.Comment #11
jhodgdonOK... Sorry for being dense. I don't always have as much familiarity with the issue as the person who made the patch. :)
So, I applied the patch and looked carefully at the drupal_form_submit() documentation that resulted. I agree with what you're saying about needing both the examples, and I think the patch is mostly OK. I would like to see a few things cleaned up though (when fixing up function docs in a patch, I usually try to get the whole function cleaned up if possible):
a)
This violates our coding standards for in-line comments (should be sentences).
b) Wrapping in the first @param should be closer to 80 characters... But really, we shouldn't have all that documentation there about hook_forms() -- it isn't all that relevant to drupal_submit_form(). Instead, maybe just say "The unique identifier for the form. See drupal_build_form() for more information.".
c) The ... parameter doc is kind of a mess, and it references a form "node_edit" which (as far as I can tell) does not actually exist in Drupal 7/8. Maybe we could reword it a bit... something like:
Any additional arguments are passed on to the functions called by drupal_form_submit(), including the form constructor function (for example, the node_form() constructor function requires a node object as its third argument). However, if the constructor function has arguments that need to be passed by reference, the arguments must be placed in $form_state['build_array']['args'] instead of passing them to drupal_form_submit() as separate arguments. For example, a form builder function with the following signature:
@code
function mymodule_form($form, &$form_state, &$object) {
}
@endcode
would be called via drupal_form_submit() as follows:
@code
$form_state['values'] = $my_form_values;
$form_state['build_info']['args'] = array(&$object);
drupal_form_submit('mymodule_form', $form_state);
@endcode
Comment #12
jhodgdonBump. This still needs a new patch, issue still exists.
Comment #13
priya.chat CreditAttribution: priya.chat at Publicis Sapient for Publicis Sapient commentedComment #14
apadernoDrupal 8 doesn't have that function anymore, so I guess it doesn't have that documentation page either. Yet, Drupal 7 has that function, and the documentation page has that "bug."
Comment #15
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedSee https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormBuilderI... for the Drupal 8 equivalent.
Comment #16
priya.chat CreditAttribution: priya.chat at Publicis Sapient for Publicis Sapient commentedComment #21
apadernoI remove the reference to the node_edit form, since it doesn't exist a form with that ID, in Drupal 8. I also removed the example using the user registration form.
Comment #22
apadernoComment #25
apadernoComment #30
manishsaharan CreditAttribution: manishsaharan commentedTry with 9.2.x
Comment #35
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #36
Nikhil_110 CreditAttribution: Nikhil_110 at Srijan | A Material+ Company commentedPatch Try with 10.1.x