Title says almost all of it.

The solution is simple:

+// 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');

Patch attached. Patch was sponsored by Peytz & Co, to ensure Hierarchical Select's compatibility with the Node Clone module: http://drupal.org/node/355226.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pwolanin’s picture

Status: Needs review » Needs work

@Wim Leers -

I'm not totally clear from the description why this existing code does not prevent the problem:

function clone_node_check($node) {

  $method = variable_get('clone_method', 'prepopulate');
  
  switch ($method) {
    case 'save-edit':
      if (variable_get('clone_nodes_without_confirm', FALSE)) {
        $new_nid = clone_node_save($node->nid);
        drupal_goto('node/'. $new_nid .'/edit');
      }
      else {
        return drupal_get_form('clone_node_confirm', $node);
      }
      break;
    case 'prepopulate':
    default:
      include_once(drupal_get_path('module', 'node') .'/node.pages.inc');
      return clone_node_prepopulate($node);
      break;
  }
}

If we want to always include node.pages.inc, then this include_once() must be removed, I think.

dawehner’s picture

I don't know why, but this patch works for me.

askibinski’s picture

I confirm the patch works but the default include doesn't.

Not sure why because clonde_node_check does include the .inc. Probably a matter of order when includes are called?

pwolanin’s picture

Version: 6.x-1.0 » 6.x-1.x-dev

This fix still looks like a bit of a hack to me - and patch still needs work per above comment.

I think the real fix is that the require might have to be inside the form building function to accommodate this case.

pwolanin’s picture

Status: Needs work » Needs review
FileSize
1.08 KB

Like this.

pwolanin’s picture

version for Drupal 5x-2.x

pwolanin’s picture

Status: Needs review » Fixed

oops - #6 is garbage - guess I confused my CVS checkouts.

committed #5.

Status: Fixed » Closed (fixed)

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

ayalon’s picture

Status: Closed (fixed) » Active

I have to reopen this issue, because the patch provided in #5 does not work as expected.

I'm using Heirarchical Select 3.4 and the latest Node Clone 6.x-dev.

Using the patch profided in the first post solved the problem completely. The patch provided by pwolanin has no impact on the problem using Hierarchical Select one cloned node form.

Reproduce:
- Install modules as described above
- Create a node Type with at least 3 hierarchies of taxonomy
- Select a taxonomy and save the node (3d level)
- Clone the node and try to select a different third level taxonomy.
- Boom: php exception and WSOD

pwolanin’s picture

Can you explain the code flow. I guess we could go with the original patch, but I'd rather not if we have a more specific way to include it.

ordually’s picture

I can confirm the issue, as documented in #9. I don't get a WSOD but do see pop up javascript death errors when attempting to change HS taxonomy on the cloned node. Applying the WimLeers patch cured it.

baff’s picture

When cloning a node which includes HS I have no problem in cloning as long as I do not change the HS values. If I want to modify HS values I have to first save the node, edit it again and then it works. I do not us a patch.

pwolanin’s picture

I'm going to "won't fix" the issue unless someone can explain the code flow to me and when the include needs to happen.

pwolanin’s picture

Status: Active » Closed (won't fix)
markdorison’s picture

Status: Closed (won't fix) » Active

I am experiencing this issue. The original patch fixes the issue for me. I believe it has something to do with the fact that the callback that the Hierarchical Select module is using is not invoking the clone_node_prepopulate() function which currently is being used to include node.pages.inc. Maybe someone with a better understanding of how HS's callback works can weigh in with some more details.

nikitas’s picture

thanx!that was really helpdfull!!!appreciated :)

Daniel Wentsch’s picture

Thanks a lot, first patch by Wim Leers worked for me (had to apply the changes manually though).

Brn’s picture

-  warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'node_form' was given in /var/.../includes/form.inc on line 377.
-  warning: uasort() [function.uasort]: The argument should be an array in /var/.../includes/common.inc on line 2944.

I thought that it was an error of HS but the problem came from NC.
Thank you very much for this patch !

douglasmiller’s picture

@pwolanin: I'm still having this issue to date. We will ignore that I am stuck using D6 on the site in question :)

You asked for an explanation of what the underlying problem is. I have been digging around and stepping through with a debugger and I think that I have an explanation for you.

The Hierarchial Select callback function, hierarchical_select_json, requests data from the cache_hierarchical_select cache for the hs_form_build_id on line 328 of HS version 6.x-3.8:

  // Collect all necessary variables.
  $cached = cache_get($hs_form_build_id, 'cache_hierarchical_select');
  $storage = $cached->data;

The data portion is an array and the 'file' index is included by HS on line 344:

  // Include the file in which the form definition function lives.
  if (!empty($storage['file'])) {
    require_once($storage['file']);
  }

During the initial clone operation, before a save, the 'file' is reported to be sites/all/modules/node_clone/clone.pages.inc. However, during a normal node editing process, the 'file' index is modules/node/node.pages.inc.

This value is set in the cache in the clone_node_prepopulate call to drupal_get_form. Specifically, it is set in hierarchical_select_after_build in HS.module which starts on line 738. The 'file' index is populated with a value obtained via a menu_get_item call. Naturally, clone.pages.inc is the value since the node/%node/clone path is implemented there.

Wim Leers' solution of adding require_once to the clone.pages.inc works because HS will "incorrectly" load the clone.pages.inc instead of node.pages.inc. Wim Leers' require_once is kind of a hotwire solution, though it works.

I suspect that you are no longer working on the D6 version, but I wanted to explain what was happening and why the patch is necessary!

douglasmiller’s picture

Status: Active » Needs review

status update