You are here

function tft_delete_term_form in Taxonomy File Tree 7.2

Same name and namespace in other branches
  1. 7 tft.admin.inc \tft_delete_term_form()

Form: delete a term.

1 string reference to 'tft_delete_term_form'
tft_menu in ./tft.module
Implementation of hook_menu().

File

includes/tft.pages.inc, line 272
Defines all page callbacks for TFT.

Code

function tft_delete_term_form($form, $form_state, $tid) {
  global $user;
  if (!tft_term_access($tid, $user, 'delete')) {
    drupal_set_message(t("You do not have access to this folder. You cannot modify or delete it."), 'error');
    if ($destination = str_replace('%23', '#', $_GET['destination'])) {
      drupal_goto($destination);
    }
    else {
      drupal_goto();
    }
  }

  // @todo OG logic !!
  if (tft_is_archive_folder($tid)) {
    drupal_set_message(t("Archive folders cannot be deleted."), 'error');
    if ($destination = str_replace('%23', '#', $_GET['destination'])) {
      drupal_goto($destination);
    }
    else {
      drupal_goto();
    }
  }
  $name = db_query("SELECT name FROM {taxonomy_term_data} WHERE tid = :tid", array(
    ':tid' => $tid,
  ))
    ->fetchField();

  // If no name was found
  if (!$name) {
    drupal_set_message(t("An error occured. The '@tid' folder could not be found. Please contac tthe site administrator.", array(
      '@tid' => $tid,
    )), 'error');
    if ($destination = str_replace('%23', '#', $_GET['destination'])) {
      drupal_goto($destination);
    }
    else {
      drupal_goto();
    }
  }

  // Check that this term has no child terms or files
  if (tft_check_term_is_deletable($tid)) {
    drupal_set_title(t("Are you sure you want to delete the folder @term ?", array(
      '@term' => $name,
    )));
    $form['tid'] = array(
      '#type' => 'hidden',
      '#value' => $tid,
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t("Delete"),
      '#attributes' => array(
        'class' => array(
          'delete-button',
        ),
      ),
    );
    $parts = explode('#', str_replace('%23', '#', $_GET['destination']));
    $form['cancel'] = array(
      '#markup' => l(t("cancel"), $parts[0], array(
        'attributes' => array(
          'class' => array(
            'tft-cancel-button',
          ),
        ),
        'fragment' => isset($parts[1]) ? $parts[1] : '',
      )),
    );
    return $form;
  }
  else {
    drupal_set_message(t("<em>@name</em> contains files and/or child folders. Move or delete these before deleting this folder.", array(
      '@name' => $name,
    )), 'error');
    if ($destination = str_replace('%23', '#', $_GET['destination'])) {
      drupal_goto($destination);
    }
    else {
      drupal_goto();
    }
  }
}