This is a rather tricky issue, but I've managed to figure out the following:

  1. When working in a unsaved clone of a node (from the node_clone module), ie. on the path node/261415/clone (where 261415 is the node we're cloning from), when you select a term with children, causing a POST to hierarchical_select_json, the POST request causes a PHP fatal error, which in turn returns no data and causes the Hierarchial Select interface to go into infinite stopwatch mode.
  2. This is due to hierarchical_select_json() passing boolean FALSE to drupal_render (which tries to += its parameter to an array), which in turn gives PHP Fatal error: Unsupported operand types in /var/www/drupal/drupal6/includes/common.inc on line 2827.
  3. The FALSE originates from _hierarchical_select_get_form_item(), since it tries to find an element of the name of 'taxonomy[4]' (in this case) in the form that's returned from drupal_retrieve_form, and since it finds no elements of that name, it returns FALSE.
  4. The reason that it finds no such element is that the form in this case is totally devoid of fields. When passed through dpm(), it looks like this: http://skitch.com/mikl/bymh4/ .
  5. The reason the form is empty is probably because there is something wrong with the data passed along from $storage['parameters'], but I have yet to figure out what it is.

I have not yet managed to find a decent workaround for this, just bypassing drupal_render when no element is found will just cause Hierarchical Select to fail in a different way, since the HTML snippet it expects is not returned.

There is perhaps more digging to be done, or perhaps a decent workaround would be to generate a new form with the same $form_id, but leaving out the state from $storage, but now I really need to sleep :)

Comments

wim leers’s picture

Assigned: Unassigned » wim leers

mikl's client, Peytz & Co, will be sponsoring this patch. Thanks mikl and Peytz & Co!

I'll work on this on Monday.

wim leers’s picture

Status: Active » Fixed
StatusFileSize
new3.37 KB
new1.14 KB

mikl has asked me to also make Hierarchical Select handle errors better (i.e. failed/erroneous callbacks to the server).

Thanks to Peytz & Co, who's sponsoring this patch, I managed to solve the problem and make HS more informative when an error occurs.

To solve the actual problem, a patch to the Node Clone module was necessary:

+// Some modules store the file that is needed in an AHAH callback. For example
+// in the case of Hierarchical Select, the node form is rebuilt in an AHAH
+// callback, which obviously requires the node_form() function to be present.
+// Hierarchical Select knows which file is necessary by looking at the file
+// for the current menu item.
+// However, when the node form is presented through the Node Clone module, a
+// different file is used: clone.pages.inc. So in order to allow the function
+// for the node form to be found, we have to include the node.pages.inc file!
+require_once(drupal_get_path('module', 'node') . '/node.pages.inc');

To make Hierarchical Select more informative in case of errors, I extended the JS quite a bit. It seems jQuery 1.2.6 behaves very differently in Safari and Firefox, which made me wonder what was going on. I got it working in the end. When an error occurs, the Drupal.HierarchicalSelect.throwError(hsid, message) gets called and:

  1. Shows the error message to the user using an alert().
  2. Logs the error.
  3. Changes the default selection back to the level label, if present, and if no level label, the <none> option, if it's present.
  4. Re-enables the form, thereby allowing the user to retry.
wim leers’s picture

I also created an issue in the Node Clone issue queue and attached the patch: http://drupal.org/node/372185.

wim leers’s picture

Title: When working with node_clone, hierarchial select passes boolean FALSE to Drupal render, causing a PHP fatal error. » HS + Node clone compatibility
wim leers’s picture

Title: HS + Node clone compatibility » HS + Node clone compatibility and making HS more informative when an error occurs

Status: Fixed » Closed (fixed)

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

pwolanin’s picture

Status: Closed (fixed) » Active

better patch for Node clone posted here: http://drupal.org/node/372185#comment-3217398

wim leers’s picture

Status: Active » Closed (fixed)

Thanks pwolanin, and great that it's gotten committed! :)

CSoft’s picture

Priority: Normal » Critical
Status: Closed (fixed) » Active

hierarchical_select 6.x-3.7 + node_clone 6.x-1.x-dev

When the cloning node and select the term, hierarchical_select.js gives an error:

"Received an invalid response from the server."

After updating the page:

warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'node_form' not found or invalid function name in \includes\form.inc on line 377.
warning: uasort() expects parameter 1 to be array, boolean given in \includes\common.inc on line 2944.

How can solve this problem? :(

kenorb’s picture

Priority: Critical » Normal
Status: Active » Closed (fixed)