Hi guys,
I need to perform same operation on nodes before a taxonomy term related to them is deleted. I used hook_taxonomy() but I'm not able to collect information about nodes. Here my code:

/**
 * Implementation of hook_taxonomy().
 */
function taxonomy_node_taxonomy($op, $type, $array = array()){
	$term_id = array($array['tid']);
	
	switch ($type) {
		case 'term':
			switch ($op) {
				case 'delete':
					// do something
					break;
			}
	}
}

Am I on the right way?

Thanks a lot

Nicolo'

Comments

mikispeed’s picture

Hi Nicolo,

take a look at http://api.drupal.org/api/function/taxonomy_select_nodes/6, you will be able to get a recordset containing nid's of nodes related to term (or terms).

Best,
M

nicoloconte’s picture

@mikispeed

I'm using it but I have no result. My purpose is to call a function before update the database. Is it possible?

mikispeed’s picture

You are right, hook_taxonomy is called after term has been deleted from DB.

I would try modifying the taxonomy_form_term form with hook_form_alter and trying something like:

function module_name_form_alter(&$form, $form_state, $form_id) {
  // Edit term form
  if($form_id == 'taxonomy_form_term'){
    if ($form_state['values']['delete'] == TRUE) {
      // Insert your code here
    }
  }
}

Best,
M