Problem/Motivation
The views_ajax_form_wrapper() function isn't well documented, and should be part of a class as it's only used in Views forms.
Proposed resolution
Move this to ViewsFormBase, with better documentation.
Remaining tasks
1. Make a patch to fix the documentation:
a) Add a one-line summary, separate from the main function description, to the top.
b) Add a note to the documentation saying it's a function for internal use in the Views UI.
c) Document the parameters:
- For $form_id, copy the docs at https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormBuilderI...
- For $form_state, say
@param array $form_state: An array that stores information about the form. See \Drupal\Core\Form\FormBuilderInterface::buildForm() for details.
d) Document the return value, which is either:
- An AjaxResponse object, for an Ajax response (be sure to include the full namespace).
- The rendered form, as a string.
- A render array with the form title and the rendered form in it.
[This is taken care of in the patch in #19]
2. Novice task -- Test manually to make sure this is working. This function/method is used to allow Views UI to use Ajax update dialogs to update views, rather than having to go to a separate page. So someone needs to apply the patch and make sure the Views UI is still working how it should. Someone familiar with how Views UI works in Drupal 7 or 8 would be good. Test a few areas of the UI screen for a view, like adding a new field, editing an existing filter, removing a sort, etc. Then add a comment to the issue explaining what you tested.
3. Novice task -- Write a draft change notice explaining that internal function views_ajax_form_wrapper() has been removed, and replaced by \Drupal\views_ui\Form/Ajax/ViewsFormBase::ajaxFormWrapper().
User interface changes
None.
API changes
The views_ajax_form_wrapper() and ajax.inc file will be removed, and replaced by a method on ViewsFormBase.
Beta phase evaluation
| Issue category | Task because it functions normally without the change (not bug). |
|---|---|
| Issue priority | Minor because it doesn't inhibit functionality. |
| Unfrozen changes | Although one of the goals of this issue is to improve documentation, it's not unfrozen because it touches file not mentioned in the 'unfrozen' section. |
| Prioritized changes | The main goal of this issue is to improve documentation and moving views_ajax_form_wrapper() to its proper place. I don't think that it's prioritized though. |
| Disruption | Disruption is minimal because only views use the function and it's also taken care of in this issue |
| Comment | File | Size | Author |
|---|---|---|---|
| #49 | interdiff-41-49.txt | 685 bytes | tadityar |
| #49 | 2303761-49.patch | 6.95 KB | tadityar |
| #41 | 2303761-41.patch | 7.08 KB | tadityar |
| #39 | 2303761-39.patch | 7.07 KB | tadityar |
| #34 | 2303761-34.patch | 7.2 KB | rpayanm |
Comments
Comment #1
jhodgdonUm. If this is a novice task, we will need more information added to the issue about what needs to be added to the documentation. Looking at https://api.drupal.org/api/drupal/core!modules!views!includes!ajax.inc/f... ... I am clueless as to what is needed.
Also... Is this an internal-use function for within Views, or something developers need to know about? If it's for developers, perhaps it needs an @ingroup line to link it up to a topic? If it's internal use... it only seems to be called in one place -- shouldn't it just be part of that class instead of being a stand-alone function?
Assigning back to dawehner for more information to be added. Please. :)
Comment #2
dawehnerYes, this is a function used just to build up the views UI.
We should document that $form_id is a form arg ('Drupal/...FooForm') which will be wrapped
Form_state is the usual form state passed along to the wrapper form.
PS: do we have a tag which is kinda novice but maybe a bit more advanced?
Comment #3
jhodgdonI don't know of a "nearly novice" tag, but if you put explicit instructions in the issue summary, one of our very capable "repeat novice" people will probably grab the issue and take care of it. Don't underestimate the novices -- we also have mentoring. :)
I've taken a stab at an issue summary.
But ... again, shouldn't this really be moved into the Views class that uses it? Why is it still in the module?
Comment #4
JayeLeBun commentedAttached you'll find a patch adding a documentation block for this function. Please let me know if I can make any improvements on the doc style for this file!
Comment #5
jhodgdonThanks for the patch! Great start! A few things to fix:
a)
The indentation here is wrong. /** should be all the way to the left, and then in the other lines, * should line up with the first * in the /** line.
b)
In the function signature, the parameter here is actually $form_class... However, probably we should change the argument to be $form_arg (will require the code to be changed, but that is OK because changing local variable names is considered a documentation change).
Also, the instructions in the issue summary said to copy some documentation; that documentation was not copied, so we don't really have all the information we need and the punctuation is not really OK.
c)
Needs line wrapping attention. "See" should be on the previous line.
d)
There should be a blank line between the @param section and the @return, and the @return line should include a type. See https://www.drupal.org/node/1354#types for how to document types.
e) The first parameter needs a type on it too.
f)
Needs : at end of line before a list. Also each list item needs to end in . See
https://www.drupal.org/node/1354#lists
g)
How about "A \Drupal\Core\Ajax\AjaxResponse object." instead?
h)
Looking at this, I realize we probably should be more explicit. The code seems to be putting the title in #title and the form in #markup array elements, so let's mention this.
Comment #6
JayeLeBun commentedThanks for that. Could you clarify a bit on this correction?
Quite a bit of documentation there! I looked at both the documentation on the FormBuilderInterface function in and then the FormBuilder.php file referenced on that page.
Comment #7
jhodgdonSorry for not being clear!
For the $form_arg parameter (well, it's currently called $form_id but we would like to rename it $form_arg), copy the docs from $form_arg on https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormBuilderI...
Comment #8
JayeLeBun commentedHere's an updated patch with changes. I realized after changing everything I failed to do an interdiff (sorry!) so I hope it's ok just submitting a new patch with changes. (Did the original patch using a different machine).
Most of the notes were pretty straightforward, but a few changes that might need attention:
-For $form_arg, I'm pretty sure I pulled the right documentation snippet but please double check.
-For the @return type, I designated as mixed and based that decision on phpDocumentor standards: http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutoria...
-Clarified the render array return for #title and #markup. Does that look ok?
Comment #9
tim.plunkettThanks for working on this!
A couple more notes.
drupal_build_form() is gone, this should reference \Drupal\Core\Form\FormBuilderInterface::buildForm() as it did before.
This is perfect now!
The second line needs to be indented one more space (should line up under the first "A" in @param).
You'll also need to wrap under 80 characters, so right after the "See".
I'd probably replace this
mixedwith\Drupal\Core\Ajax\AjaxResponse|string|arrayEach of these lines should be indented one more space
Comment #10
pushpinderchauhan commentedUpdated patch with #9 changes. Please review.
Comment #11
JayeLeBun commentedI see the changes and tests passed. Thanks for the assist, this was my first patch!
Comment #12
tim.plunkettYay! Congrats @jessi_pantheon, great work. Thanks @er.pushpinderrana for the last push.
Comment #13
amitgoyal commentedI believe following line should split into 2 lines so that 80 characters limit can be maintained,
+ * - A render array with the title in #title and the rendered form in the #markup array.
Please review the updated patch for the same.
Comment #14
tim.plunkettClose enough ;)
Thanks @amitgoyal.
Comment #15
jhodgdonUm... This bit in the @return isn't quite right:
Last word should be "property".
Can we fix up the top of this documentation too? Sorry for not mentioning this sooner...
- The first line should start with a verb, and tell what the function does, like "Handles Ajax forms for the Views module.".
- AJAX should be Ajax.
- The next paragraph... "automatically"? "some Ajax stuff"? "some assumptions"? Really this is not very good documentation. But at a minimum, it should be wrapped better.
I took a look at what this function actually does, and would like to propose replacing the 2nd paragraph with:
Builds the form and either creates an Ajax response that displays it as a dialog, or returns the rendered form.
Also, can I just ask again: Why is this function not a method on the Views class that is the only place it is called, rather than being a stand-alone function?
Comment #18
tim.plunkettBecause "document" generally doesn't include refactoring. Expanding the scope.
Comment #19
tim.plunkettIt would help to call the new method.
Comment #21
jhodgdonhah! Now we're talking:
!!
I am definitely +1 on this patch.
I suppose we should make sure this is working though? This is used in the Views UI module for all the places with Ajax forms, I think. So we should test and make sure that it's working. I do not think that the automated tests will catch possible problems with this patch, because as far as I know they are not able to test Ajax/JavaScript behavior.
Comment #22
roderikTagging for Amsterdam.
Suggestion:
- start with updating the issue summary with the task you need to do, which is what jhodgdon says.
- do it :)
- comment on what you have tested manually.
Comment #23
jhodgdonUpdated the issue summary with remaining tasks.
Comment #24
jhodgdonAs this latest patch is an API change, we also need a brief draft change notice written.
Comment #25
guntervs commentedWill do the manual testing.
Comment #26
guntervs commentedComment #27
guntervs commentedManual testing failed, since $form_state is a classed object now. I'll try to update the code.
Comment #28
guntervs commentedReplaced the code in ajaxFormWrapper with the one in ajax.inc.
Comment #29
tim.plunkettWhere's the rest of the patch? It's missing ajax.inc changes. Also please provide an interdiff against #19.
Comment #30
jhodgdonComment #31
guntervs commentedMy bad. I'll provide the complete patch later today.
Comment #32
guntervs commentedComplete patch. Somehow patchutils keeps giving errors on creating the interdiff.
Comment #33
jhodgdonThanks!
This is not the right syntax:
The blank lines here should not be added. Reference for how we do @tags is
https://drupal.org/node/1354
Also, this has too much indentation:
Please fix up the patch; I stopped looking there. The changes you made to existing code were wrong...
Comment #34
rpayanmRerolling with a fresh git pull and from patch #19 :D
Comment #35
naveenvalechaWrote the Change Record(its my first one). https://www.drupal.org/node/2383927
Let me know the improvements if needed.
Comment #36
jhodgdonThe formatting for the documentation header for the new method is still not right -- mostly indentation and wrapping issues. Please look at the sections at
https://www.drupal.org/node/1354#functions
https://www.drupal.org/node/1354#lists
for examples and standards.
The change record draft looks pretty good, although I think maybe it should say somewhere that your class would need to extend ViewsFormBase (and give the full namespace of this class!) rather than just saying it changed to using $this->ajaxFormWrapper() without context of what $this is?
Comment #37
naveenvalecha@jhodgdon,
Updated the CR as specified.Although I think there is no other place where views_ajax_form_wrapper is using through out the code in D8. Similarly in D7 views_ajax_form_wrapper . Do we need to specify in the CR how do we use this function in contrib module with example ?
Comment #38
jhodgdonI edited the change record.
The patch still needs work, see #36.
Comment #39
tadityar commentedCorrected indentation and wrapping. Please correct me if I'm wrong.
Sorry, I can't create an interdiff because the previous file doesn't apply.
Comment #40
dawehnerI am confused ... the other hunk above does not add some CSS at the moment ... maybe this is a leftover from previous versions?
Comment #41
tadityar commented@dawehner it's already there from @tim.plunkett's patch in #19 But do you think that I should remove it?
Since I think I made a mistake on indenting some part of the docs I'm attaching a patch to fix that.
Comment #42
dawehner@tadityar
Thank you for working on things, it is quite amazing how you run through all those issues.
You are right, in earlier versions of views, we used to include the css file here.
See the hunk in the patch:
...
Now that we no longer have that in the original code we also don't need to add it again :)
Comment #43
dawehner@tadityar
Can you create a small change record as well as fill out the beta evaluation again? Thanks
Comment #44
tadityar commentedAdded a draft change records here https://www.drupal.org/node/2398961 ,added beta evaluation, and changed the status.
Comment #45
tadityar commentedComment #46
dawehnerAlright, awesome!
Comment #47
alexpottAfter discussions with @catch - My first thought is to punt to 8.1 but implementing a BC layer would onerous. Given that views has been brought in from contrib and has plenty of legacy code like this and the clean up has no disruption on core I'm going to commit under the committer discretion provision in the beta policy.
As per #42 this does not need to be here.
Comment #48
tadityar commentedworking on this
Comment #49
tadityar commentedOkay, fixed that.
Comment #50
tadityar commentedSorry, forgot to change the status
Comment #51
dawehnerUps, I totally forgot my previous review :)
Comment #52
alexpottCommitted 7b83db3 and pushed to 8.0.x. Thanks!
Thanks for including the beta evaluation in the issue summary.
Comment #55
quietone commentedpublish the change record.