You are here

function flag_lists_flag_delete in Flag Lists 7

Same name and namespace in other branches
  1. 6 flag_lists.module \flag_lists_flag_delete()
  2. 7.3 flag_lists.module \flag_lists_flag_delete()

Implementation of hook_flag_delete().

This is not in flag yet.

File

./flag_lists.module, line 860
The Flag Lists module.

Code

function flag_lists_flag_delete($flag) {

  // Template flag is being deleted. Clean up our tables.
  // Collect the sub-flag fids so we can delete counts and content records.
  $results = db_select('flag_lists_flags', 'f')
    ->fields('f', array(
    'fid',
    'name',
  ))
    ->condition('pfid', $flag->fid)
    ->execute();
  foreach ($results as $fid) {
    db_delete('flag_lists_counts')
      ->condition('fid', $flag->fid)
      ->execute();
    db_delete('flag_lists_content')
      ->condition('fid', $flag->fid)
      ->execute();
  }

  // flag_lists_types uses the template flag name, not our own fid.
  db_delete('flag_lists_types')
    ->condition('name', $flag->name)
    ->execute();

  // Now delete the sub-flags.
  $num_deleted = db_delete('flag_lists_flags')
    ->condition('pfid', $flag->fid)
    ->execute();
  if (!empty($num_deleted)) {
    drupal_set_message(t('The template flag "@title" and all its sub-flags have been deleted.', array(
      '@title' => $flag->title,
    )));
  }
}