Index: addnode.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/addnode/addnode.js,v
retrieving revision 1.2
diff -u -r1.2 addnode.js
--- addnode.js 2 May 2007 17:53:47 -0000 1.2
+++ addnode.js 11 Sep 2007 16:42:14 -0000
@@ -20,8 +20,10 @@
$('span.addnode_links').click(function()
{
fieldid=this.id;
+ /*
$('select.addnode_select').filter('[@id='+fieldid+']').attr("disabled", true);
$('select.addnode_select').filter('[@id='+fieldid+']').selectNone();
+ */
});
//click on particular form type
Index: addnode.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/addnode/addnode.module,v
retrieving revision 1.2
diff -u -r1.2 addnode.module
--- addnode.module 2 May 2007 17:53:47 -0000 1.2
+++ addnode.module 17 Sep 2007 13:58:35 -0000
@@ -99,7 +99,8 @@
return $form;
}
//converts the type name to a human readable one
- $typedesc = node_get_types('type', $typedesc)->name;
+ $typedesc = node_get_types('type', $typedesc);
+ $typedesc = $typedesc->name;
//If there's more than one type available then we use the term 'item' to describe them
if ($type_count>1)
@@ -291,11 +292,34 @@
$fieldname = $subform['#fieldname'];
$split = explode("/", $redirect);
$newnid = $split[1];
+
+ //panis 09/14/07 - the original code replaced the current nids in the
+ //form with the single nid extracted from above. We would like to
+ //preserve the values if available and add the new nid to the new
+ //list. Code below is the original code and comment.
+
//unset the current array, and replace it with a new array.
//note that as multiselect is currently set, this is an array
// @todo allow multi/single select!!
- unset($form_values[$fieldname]['nids']);
- $form_values[$fieldname]['nids'] = array ( $newnid => $newnid );
+ //unset($form_values[$fieldname]['nids']);
+
+ $form_values[$fieldname]['nids'] =array_merge(array ( $newnid => $newnid ), $form_values[$fieldname]['nids']);
+
+ //panis 09/14/07 - We also want to allow the user to continue editing
+ //the current node when a new addnode is created - the original
+ //behavior would have returned the user back to the "view" node page
+ //making the user click on edit to get back to editing. This patch
+ //allows the user to remain in the edit page if a new addnode element
+ //is created. The only way we can communicate this is to set a cookie
+ //that a new "addnode" was created and use this to redirect drupal
+ //back to the edit page if the cookie is set. This is the cleanest
+ //mechanism to communicate because control is not passed back to
+ //the subform element after the parent CCK node is created. In this
+ //implementation - the hook_nodeapi looks for this cookie and if set
+ //redirects back to the edit page. May have sideeffects if the user
+ //adruptly ends the editing session midway - but not sure how we can
+ //address that.
+ $_SESSION['nodeapi_load_edit'] = drupal_get_destination();
}
}
return $redirect;
@@ -322,7 +346,8 @@
if ($type_count==1)
{
$atype=$type_list[0];
- $typedesc = node_get_types('type', $atype)->name;
+ $typedesc = node_get_types('type', $atype);
+ $typedesc = $typedesc->name;
//pretransmsg is message before translation.
$pretransmsg = "or ";
@@ -342,7 +367,8 @@
$tempcnt=0;
foreach ($type_list as $atype)
{
- $typedesc = node_get_types('type', $atype)->name;
+ $typedesc = node_get_types('type', $atype);
+ $typedesc = $typedesc->name;
$msg.= "";
$msg.= $spanmsg;
$msg.= "$typedesc";
@@ -362,3 +388,24 @@
$msg .= "";
return $msg;
}
+
+
+/**
+ * implementation of hook_nodeapi
+ * panis 09/14/07 - return the user back to the edit page of the master CCK node
+ * after adding a new nodapi element. The hook looks for a "view" operation
+ * and if the session variable signalling a "new" addnode element is set then
+ * redirects the user back to the edit page.
+ **/
+function addnode_nodeapi(&$node, $op, $arg) {
+ switch ($op) {
+ case 'view':
+ if( $_SESSION['nodeapi_load_edit'] ) {
+ unset($_SESSION['nodeapi_load_edit']);
+ $url = 'node/'.$node->nid.'/edit';
+ drupal_goto($url);
+ }
+ break; //redundant.
+ }
+}
+