You are here

function pathauto_admin_delete in Pathauto 6

Same name and namespace in other branches
  1. 5.2 pathauto.module \pathauto_admin_delete()
  2. 6.2 pathauto.admin.inc \pathauto_admin_delete()
  3. 7 pathauto.admin.inc \pathauto_admin_delete()

Menu callback; select certain alias types to delete.

1 string reference to 'pathauto_admin_delete'
pathauto_menu in ./pathauto.module
Implements hook_menu().

File

./pathauto.admin.inc, line 394
Admin page callbacks for the Pathauto module.

Code

function pathauto_admin_delete() {

  /* TODO:
     1) all - DONE
     2) all node aliases - DONE
     4) all user aliases - DONE
     5) all taxonomy aliases - DONE
     6) by node type
     7) by taxonomy vocabulary
     8) no longer existing aliases (see http://drupal.org/node/128366 )
     9) where src like 'pattern' - DON'T DO
     10) where dst like 'pattern' - DON'T DO
    */
  $form['delete'] = array(
    '#type' => 'fieldset',
    '#title' => t('Choose aliases to delete'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );

  // First we do the "all" case
  $total_count = db_result(db_query('SELECT count(1) FROM {url_alias}'));
  $form['delete']['all_aliases'] = array(
    '#type' => 'checkbox',
    '#title' => t('All aliases'),
    '#default_value' => FALSE,
    '#description' => t('Delete all aliases. Number of aliases which will be deleted: %count.', array(
      '%count' => $total_count,
    )),
  );

  // Next, iterate over an array of objects/alias types which can be deleted and provide checkboxes
  $objects = module_invoke_all('path_alias_types');
  foreach ($objects as $internal_name => $label) {
    $count = db_result(db_query("SELECT count(1) FROM {url_alias} WHERE src LIKE '%s%%'", $internal_name));
    $form['delete'][$internal_name] = array(
      '#type' => 'checkbox',
      '#title' => $label,
      // This label is sent through t() in the hard coded function where it is defined
      '#default_value' => FALSE,
      '#description' => t('Delete aliases for all @label. Number of aliases which will be deleted: %count.', array(
        '@label' => $label,
        '%count' => $count,
      )),
    );
  }

  // Warn them and give a button that shows we mean business
  $form['warning'] = array(
    '#value' => '<p>' . t('<strong>Note:</strong> there is no confirmation. Be sure of your action before clicking the "Delete aliases now!" button.<br />You may want to make a backup of the database and/or the url_alias table prior to using this feature.') . '</p>',
  );
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Delete aliases now!'),
  );
  return $form;
}