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

Reference: https://www.drupal.org/core/beta-changes
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

Comments

jhodgdon’s picture

Assigned: Unassigned » dawehner
Status: Active » Postponed (maintainer needs more info)

Um. 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. :)

dawehner’s picture

Issue tags: -Novice

Yes, 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?

jhodgdon’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active
Issue tags: +Novice

I 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?

JayeLeBun’s picture

Status: Active » Needs review
StatusFileSize
new1.2 KB

Attached 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!

jhodgdon’s picture

Status: Needs review » Needs work

Thanks for the patch! Great start! A few things to fix:

a)

+ /**
+ * Wrapper for handling AJAX forms.

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)

+ * @param $form_id
+ *   The name of the form arg ('Drupal/...FooForm') which will be wrapped.

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)

+ *   An array that stores information about the form.
+ *   See \Drupal\Core\Form\FormBuilderInterface::buildForm() for details.

Needs line wrapping attention. "See" should be on the previous line.

d)

+ *   See \Drupal\Core\Form\FormBuilderInterface::buildForm() for details.
+ * @return

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)

+ *   Returns one of three possible values

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)

+ *   - An AjaxResponse object, for an Ajax response: Drupal\Core\Ajax\AjaxResponse

How about "A \Drupal\Core\Ajax\AjaxResponse object." instead?

h)

+ *   - A render array with the form title and the rendered form in it.

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.

JayeLeBun’s picture

Thanks for that. Could you clarify a bit on this correction?

b) 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.

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.

jhodgdon’s picture

Sorry 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...

JayeLeBun’s picture

StatusFileSize
new1.74 KB

Here'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?

tim.plunkett’s picture

Thanks for working on this!

A couple more notes.

  1. +++ b/core/modules/views/includes/ajax.inc
    @@ -10,11 +10,25 @@
    - * Wrapper around \Drupal\Core\Form\FormBuilderInterface::buildForm() to handle
    ...
    + * Wrapper around drupal_build_form to handle some AJAX stuff automatically.
    

    drupal_build_form() is gone, this should reference \Drupal\Core\Form\FormBuilderInterface::buildForm() as it did before.

  2. +++ b/core/modules/views/includes/ajax.inc
    @@ -10,11 +10,25 @@
    + * @param \Drupal\Core\Form\FormInterface|string $form_arg
    + *   The value must be one of the following:
    + *   - The name of a class that implements \Drupal\Core\Form\FormInterface.
    + *   - An instance of a class that implements \Drupal\Core\Form\FormInterface.
    

    This is perfect now!

  3. +++ b/core/modules/views/includes/ajax.inc
    @@ -10,11 +10,25 @@
    + * @param array $form_state
    + *  An array that stores information about the form. See \Drupal\Core\Form\FormBuilderInterface::buildForm() for details.
    

    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".

  4. +++ b/core/modules/views/includes/ajax.inc
    @@ -10,11 +10,25 @@
    + * @return mixed
    

    I'd probably replace this mixed with \Drupal\Core\Ajax\AjaxResponse|string|array

  5. +++ b/core/modules/views/includes/ajax.inc
    @@ -10,11 +10,25 @@
    + *  Returns one of three possible values:
    + *  - A \Drupal\Core\Ajax\AjaxResponse object.
    + *  - The rendered form, as a string.
    + *  - A render array with the title in #title and the rendered form in the #markup array.
    

    Each of these lines should be indented one more space

pushpinderchauhan’s picture

Status: Needs work » Needs review
StatusFileSize
new1.71 KB
new1.63 KB

Updated patch with #9 changes. Please review.

JayeLeBun’s picture

I see the changes and tests passed. Thanks for the assist, this was my first patch!

tim.plunkett’s picture

Assigned: dawehner » Unassigned
Status: Needs review » Reviewed & tested by the community

Yay! Congrats @jessi_pantheon, great work. Thanks @er.pushpinderrana for the last push.

amitgoyal’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.72 KB
new628 bytes

I 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.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Close enough ;)
Thanks @amitgoyal.

jhodgdon’s picture

Status: Reviewed & tested by the community » Needs work

Um... This bit in the @return isn't quite right:

+ *   - A render array with the title in #title and the rendered form in the
+ *     #markup array.
 

Last word should be "property".

Can we fix up the top of this documentation too? Sorry for not mentioning this sooner...

/**
+ * Wrapper for handling AJAX forms.
+ *
  * Wrapper around \Drupal\Core\Form\FormBuilderInterface::buildForm() to handle
  * some AJAX stuff automatically.
  * This makes some assumptions about the client.

- 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?

The last submitted patch, 13: drupal8-docviewsajax-2303761-13.patch, failed testing.

tim.plunkett’s picture

Title: document views_ajax_form_wrapper() » Move views_ajax_form_wrapper() to ViewsFormBase
Component: documentation » views_ui.module
Status: Needs work » Needs review
StatusFileSize
new6.27 KB

Because "document" generally doesn't include refactoring. Expanding the scope.

tim.plunkett’s picture

StatusFileSize
new7.3 KB
new1.3 KB

It would help to call the new method.

The last submitted patch, 18: vdc-2303761-18.patch, failed testing.

jhodgdon’s picture

Issue tags: +Needs manual testing

hah! Now we're talking:

    // @todo Remove the need for this.
     \Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');
-    \Drupal::moduleHandler()->loadInclude('views', 'inc', 'includes/ajax');

!!

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.

roderik’s picture

Tagging 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.

jhodgdon’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated the issue summary with remaining tasks.

jhodgdon’s picture

Issue summary: View changes
Issue tags: +Needs change record

As this latest patch is an API change, we also need a brief draft change notice written.

guntervs’s picture

Will do the manual testing.

guntervs’s picture

Assigned: Unassigned » guntervs
guntervs’s picture

Status: Needs review » Needs work

Manual testing failed, since $form_state is a classed object now. I'll try to update the code.

guntervs’s picture

Assigned: guntervs » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.84 KB

Replaced the code in ajaxFormWrapper with the one in ajax.inc.

tim.plunkett’s picture

Where's the rest of the patch? It's missing ajax.inc changes. Also please provide an interdiff against #19.

jhodgdon’s picture

Status: Needs review » Needs work
guntervs’s picture

Assigned: Unassigned » guntervs

My bad. I'll provide the complete patch later today.

guntervs’s picture

Assigned: guntervs » Unassigned
Status: Needs work » Needs review
StatusFileSize
new7.6 KB

Complete patch. Somehow patchutils keeps giving errors on creating the interdiff.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks!

This is not the right syntax:

+++ b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
@@ -1,7 +1,9 @@
 <?php
 
 /**
+ *
  * @file
+ *

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:

   * @param string $type
-   *   The type of the item this form is manipulating.
+    *    The type of the item this form is manipulating.
    */

Please fix up the patch; I stopped looking there. The changes you made to existing code were wrong...

rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new7.2 KB

Rerolling with a fresh git pull and from patch #19 :D

naveenvalecha’s picture

Wrote the Change Record(its my first one). https://www.drupal.org/node/2383927
Let me know the improvements if needed.

jhodgdon’s picture

Status: Needs review » Needs work

The 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?

naveenvalecha’s picture

@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 ?

jhodgdon’s picture

I edited the change record.

The patch still needs work, see #36.

tadityar’s picture

Status: Needs work » Needs review
StatusFileSize
new7.07 KB

Corrected indentation and wrapping. Please correct me if I'm wrong.
Sorry, I can't create an interdiff because the previous file doesn't apply.

dawehner’s picture

+++ b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
@@ -178,6 +178,78 @@ public function getForm(ViewStorageInterface $view, $display_id, $js) {
+      $form['#attached']['css'][] = drupal_get_path('module', 'views_ui') . '/css/views_ui.admin.css';

I am confused ... the other hunk above does not add some CSS at the moment ... maybe this is a leftover from previous versions?

tadityar’s picture

StatusFileSize
new7.08 KB
+++ b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
@@ -180,6 +180,74 @@ public function getForm(ViewStorageInterface $view, $display_id, $js) {
+      $form['#attached']['css'][] = drupal_get_path('module', 'views_ui') . '/css/views_ui.admin.css';

@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.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

@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:

-
-  // These forms have the title built in, so set the title here:
-  if (empty($form_state['ajax']) && !empty($form_state['title'])) {
-    $form['#attached']['css'][] = drupal_get_path('module', 'views_ui') . '/css/views_ui.admin.css';
-  }

...

Now that we no longer have that in the original code we also don't need to add it again :)

dawehner’s picture

Status: Reviewed & tested by the community » Needs work

@tadityar
Can you create a small change record as well as fill out the beta evaluation again? Thanks

tadityar’s picture

Issue summary: View changes
Priority: Normal » Minor
Status: Needs work » Needs review

Added a draft change records here https://www.drupal.org/node/2398961 ,added beta evaluation, and changed the status.

tadityar’s picture

Issue summary: View changes
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Alright, awesome!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs change record

After 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.

+++ b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
@@ -178,6 +178,78 @@ public function getForm(ViewStorageInterface $view, $display_id, $js) {
+    if (!$ajax && $title) {
+      $form['#attached']['css'][] = drupal_get_path('module', 'views_ui') . '/css/views_ui.admin.css';
+    }

As per #42 this does not need to be here.

tadityar’s picture

Assigned: Unassigned » tadityar

working on this

tadityar’s picture

Assigned: tadityar » Unassigned
StatusFileSize
new6.95 KB
new685 bytes

Okay, fixed that.

tadityar’s picture

Status: Needs work » Needs review

Sorry, forgot to change the status

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Ups, I totally forgot my previous review :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7b83db3 and pushed to 8.0.x. Thanks!

Thanks for including the beta evaluation in the issue summary.

  • alexpott committed 7b83db3 on 8.0.x
    Issue #2303761 by tadityar, tim.plunkett, guntervs, jessi_pantheon, er....

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

quietone’s picture

publish the change record.