DEFINITION: 'delete pre' case of hook_nodeapi DESCRIPTION: Inject module-specific data into the delete confirmation screen. Note: This hook operates prior to the actual deletion of nodes, allowing modules to place both informational messages and control structures into the confirmation step of the process, as well as providing a mechanism allowing modules to prevent deletion of a node. The hook is called for both single node deletions and admin batch deletions. RETURN VALUE An HTML string representing the data to inject, or explicitly return FALSE if preventing the deletion of the node is desired (on single node deletions, this will return the user to the node/edit page. for admin batch deletions, this will remove the node from the batch queue prior to the confirmation screen. also, informing the user of the action via drupal_set_message is suggested). Alternately, an array of values may be returned, each one an HTML string representing the data to inject. example: '

This is the last one of it's kind!

' OR array('

This is the last one of it's kind!

', form_textfield('Enter log message for this deletion', 'logmessage]['.$node->nid, '', 40, 40)); CODE EXAMPLES: This example demonstrates how to inject custom messages into the delete confirmation screen, and also how to cancel deletion of a node: function example_nodeapi(&$node, $op) { switch ($op) { case 'delete pre': //if the node has any signups, prevent deletion and warn if ($user_signups = db_num_rows(db_query('SELECT nid FROM {example_log} WHERE nid = %d', $node->nid))) { $data_to_inject = array(FALSE); drupal_set_message(t('%title cannot be deleted, %d user(s) signed up for this event. Delete all signups for the event in order to delete the event.', array('%title'=>$node->title, '%d'=>$user_signups))); } else { $data_to_inject = t('No users signed up for this event'); } return $data_to_inject; break; } } This example demonstrates how to inject a custom control structure into the delete confirmation screen: function example_nodeapi(&$node, $op) { switch ($op) { case 'delete pre': if (variable_get('example_nodeapi_'. $node->type, 'never')) { //create the option arrays $options = array('this' => t('This occurance only'), 'future' => t('This occurance and all future occurances'), 'all' => t('All occurances') ); //for any nodes that need delete confirm data injected, construct the radio buttons and add the nodes data //to the data_to_inject array. NOTE: in order to prevent name collisions in the admin //delete process for multiple nodes, these HTML elements are named in array fashion, with nid to distinguish //the elements of the array $data_to_inject = array(form_radios(t('Repeat event--delete the following'), 'example_delete_type]['.$node->nid, 'this', $options, $description = t('\'This occurance and all future occurances\' will delete repeat events from the date of the selected node forward,\'All occurances\' will delete repeat events from today\'s date forward.'), $required = FALSE, $attributes = NULL)); return $data_to_inject; } break; } } IMPORTANT NOTE: When deletion occurs the control structure's data will be available via the $_POST['edit'] array. It's highly recommended to unset the value for the control structure once it's data has been captured to avoid the possibility of endless loops.