diff --git a/node_adoption.module b/node_adoption.module index b5c3a4f..0ac0097 100644 --- a/node_adoption.module +++ b/node_adoption.module @@ -128,4 +128,102 @@ function node_adoption_form_transfer_submit($form_id, $form_values) { return 'admin/content/node_adoption'; } -?> \ No newline at end of file + +/** + * Below here is the alternate interface + * + * - integrated with the normal Drupal content management page. + */ + +/** + * Hook Implimentation + */ +function node_adoption_form_alter($form_id, &$form) { + // Enhance the node overview page + if ($form_id == 'node_admin_nodes') { + node_adoption_content_form_alter($form); + } +} + +/** + * Add a bulk classification function to the content admin + */ +function node_adoption_content_form_alter(&$form){ + // support bulk classifications + $form['options']['operation']['#options']['set_new_owner'] = t('Assign a new owner'); + + $form['options']['new-owner-wrapper'] = array( + '#type' => 'fieldset', + '#attributes' => array('id' => 'fs-new-owner', 'style'=>'display:none;'), + 'new_owner' => array( + '#type' => 'textfield', + '#title' => t("New owner"), + '#default_value' => '', + '#autocomplete_path' => 'user/autocomplete', + '#maxlength' => 60, + '#size' => 40, + '#description' => t("Assign all selected nodes to this new owner"), + ), + ); // used the extra fieldset because renderer was failing to honour doing the same via #prefix + $form['#submit']['node_adoption_content_form_submit'] = array(); + + drupal_add_js(node_adoption_content_form_javascript(),'inline'); +} + +/** + * Capture additional operations on the content management page + * @see node_admin_nodes_submit() + */ +function node_adoption_content_form_submit($form,$edit){ + if ($edit['operation'] == 'set_new_owner') { + $new_owner = $edit['new_owner']; + $u = user_load(array('name' => $new_owner)); + $urep = array('%user' => $new_owner); + if (isset($u) && is_object($u)) { // user found -> change owner + $sel_nodes = array(); + foreach ($edit['nodes'] as $nid => $checked) { + if ($checked) $sel_nodes[] = $nid; + } + if (!empty($sel_nodes)) { + // TODO: find clever way to update node & node_revisions table + // without loading and saving all node 1 per 1 +// $nid_str = implode("','", $sel_nodes); +// db_query("UPDATE {node} SET uid = %d WHERE nid IN ('". +// $nid_str ."')", $u->uid); + foreach ($sel_nodes as $nid) { + $n = node_load($nid); + $n->uid = $u->uid; + node_save($n); + } + drupal_set_message(t('Updated owner to %user', $urep)); + //cache_clear_all(); + } + } + else { + drupal_set_message(t('User %user not found', $urep), 'error'); + } + } +} + +function node_adoption_content_form_javascript(){ + // quoted javascript: + return <<