[support] Problem with menus

Richard Damon Richard at Damon-Family.org
Sun Jun 9 19:45:44 UTC 2013


I am having some problems with a form being generated via ctools in
drupal 7, and looking for help. At first glance it seems to be a very
fundamental bug, but it is hard to imagine that a bug like this could
have gone so long without affecting someone else.

System Info:
PHP 5.3.18
Drupal Core 7.22 (Latest Stable)
CTools 7.x-1.3 (Latest Stable)

The symptom I was seeing was that a select control wasn't taking its new
value, but keeping its old value. In tracing it back, I found that when
the form was loaded from cache on the submission, the form control had a
#value property for the old setting, which override the new value. In
tracing that back I found

in /includes/form.inc
is the function:
function drupal_process_form($form_id, &$form, &$form_state) {
...
  $unprocessed_form = $form;
  $form = form_builder($form_id, $form, $form_state);

I modified this to be:

  $unprocessed_form = $form;
  dpm($unprocessed_form);
  $form = form_builder($form_id, $form, $form_state);
  dpm($unprocessed_form);


and I see that the value of $unprocessed_form changes in the call to
form_builder, which created the #value property from the #default_value
property created for the control.
I think this is because form is really just a reference to the render
array for the form, so $unprocessed_form was set to be another reference
to that same render array, so changes to the array are reflected in
$unprocessed_form.

It appears that we need to do something to "deep-copy" the value of the
form here to save the old value.

The problem I have is that it is hard to imagine that this hasn't bitten
anyone previously, so maybe I am doing something wrong in the first
place in building my form, but it is hard to imagine that I could be
doing something so wrong as to mess up code this far from the code I am
writing in such a way.

Any ideas on this? Do I submit an issue on this, or it the problem on my
end?

-- 
Richard Damon



More information about the support mailing list