This makes AHAH fairly unusable. Of course, this is not purely AHAH fault, there is some juggling to be done before a #process somewhere deep down in the form array can flip #cache. Namely, we need to copy back the #cache to the top and also we need to do the caching past processing.

Some concerns: a) but drupal_process_form does not return always, what happens on redirect? Well, when we redirect then the form cycle is over (you no longer have the build_id so the cache etc, so the cacheable is not reachable anyways). b) why not simply $complete_form = &$form; and pass along complete_form by reference? Well, this simply does not work, on the second form_builder call complete_form becomes NULL, the static does not stick. I guess $form is a local var and the reference simply does not point anywhere in subsequent calls.

Note: The _form_builder_handle_input_element change is just a cleanup as we longer pass a variable number of arguments, we can just use $function which results in simpler code.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

FileSize
3.67 KB

This lets us remove the #cache from the AHAH poll edit form and that gives us an excellent opportunity to test the changes. Of course, book and menu could see #cache removed but I would rather not distrurb them when the whole of parent chooser is being rehauled...

All in all, after this patch is in we can have standalone form elements that use AHAH like the drilldown in http://drupal.org/node/191360 . It's good I am doing such a complex form, all these flaws surface before release. Yay.

chx’s picture

FileSize
4.13 KB

More comments.

chx’s picture

Title: AHAH can't set #cache » Using AHAH on custom elements is not possible
FileSize
6.79 KB

Well, there is a bit more than the above that's needed. One, I factored out drupal_rebuild_form because that's needed and also I added an #array_parents to make it easier to find ourselves.

quicksketch’s picture

This is a very handy improvement. Previously, only the top-level form was able to set the #cache property. This is still the case, but now any element within the form can also enable #cache. The use-case for this is defining a custom form element via hook_elements(). If that element were to implement AHAH functionality, it would have no way of setting or retrieving the cached form. This patch makes it so that any element can set #cache, then retrieve the pertinent data during the AHAH request.

Without this patch, no custom element defined by core or contrib will be able to leverage the AHAH framework. I'm not keen enough to review the form.inc code other than style (which looks great), but in testing this patch doesn't break Poll which uses the #cache property.

chx’s picture

FileSize
8.26 KB

Same code just added Eaton-amount ;) comments.

Gábor Hojtsy’s picture

Status: Needs review » Needs work

- I don't understand how the #array_parents changes are related.
- I don't see how the #process callback reorganization is related, although that array_merge() looks definitely freaky.
- "Rebuilds a form based on form_state." We know this from the function name... What's a form rebuilding?
- "This function clear $_POST" should be "clears"

chx’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
8.35 KB

Then send back a part of the returned form. $form_state['clicked_button']['#array_parents'] will help you to find which part.

So you are an element somewhere in the form tree. How will the AHAH callback find the element in the rebuilt form? Currently it has no way unless you set #tree TRUE on the form root when #parents becomes the same as the new #array_parents. With #array_parents, and a rebuilt form, you can take the $form_state['clicked_button']['#array_parents'] and do (actual code from menu_form_js):

  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
  // Pick up the parents of the pressed button.
  $array_parents = $form_state['clicked_button']['#array_parents'];
  // The last parent is the button itself, we need the wrapper instead.
  array_pop($array_parents);
  while ($array_parents) {
    $parent = array_shift($array_parents);
    $form = $form[$parent];
  }

And then you have $form ready to be sent back to the client. You just walk the form tree the same way as in the original form. #array_parents is the thread of Ariadne.

Note: The _form_builder_handle_input_element change is just a cleanup as we longer pass a variable number of arguments, we can just use $function which results in simpler code.

(this from the original post)

What's a form rebuilding? and the clears typo is fixed in the attached patch. Also in the future could you please tell me on IM too if you have problems like this -- a five minute, trivial comment change now postponed the patch for another day :(

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

chx: IM-ing with you moves the patch review process out of public eyes. I'd like to keep the review process as public as possible, so people see on what grounds patches are modifies, what was not right, etc.

Gábor Hojtsy’s picture

Also, you commented after two hours on my follow up, which is not exactly one day in my calendar.

chx’s picture

Status: Needs work » Reviewed & tested by the community

I said "too". A simple "http://drupal.org/node/193191#comment-634164" on Skype is more than enough because then I know I need to deal with something.

chx’s picture

FileSize
8.29 KB

Fixed the summary to be one line.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

OK, thanks, committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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