Node clone fails in case of AJAX callbacks because the file associated with the menu item doesn't include node_form()
Wim Leers - February 10, 2009 - 15:44
| Project: | Node clone |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Wim Leers |
| Status: | needs work |
Jump to:
Description
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.
| Attachment | Size |
|---|---|
| node_clone_ahah_callback_support.patch | 1.14 KB |

#1
@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.
#2
I don't know why, but this patch works for me.