1 path.admin.inc | path_bulk_update_form_bulk_delete_submit($form, &$form_state) |
Submit handler for path_admin_bulk_delete().
File
- core/
modules/ path/ path.admin.inc, line 943 - Admin page callbacks for the Path module.
Code
function path_bulk_update_form_bulk_delete_submit($form, &$form_state) {
$values = array();
$count_base = 0;
// Filter out empty choices and count how many entity types had all subtypes
// selected.
foreach ($form_state['values']['delete'] as $key => $value) {
$value = array_filter($value);
if ($value) {
if (isset($value['base'])) {
$count_base++;
}
$values[$key] = $value;
}
}
if ($values) {
$all_path_info = path_get_info();
// If all entities are to have all aliases deleted, skip straight to delete.
if ($count_base === count($all_path_info)) {
db_delete('url_alias')
->execute();
backdrop_set_message(t('All of your URL aliases have been deleted.'));
}
else {
foreach ($values as $key => $value) {
// For those entities where all aliases need to be deleted, delete using
// a LIKE query.
if (isset($value['base'])) {
if (array_key_exists($key, $all_path_info)) {
$path_prefix = isset($all_path_info[$key]['source prefix']) ? $all_path_info[$key]['source prefix'] : $key . '/';
db_delete('url_alias')
->condition('source', db_like($path_prefix) . '%', 'LIKE')
->execute();
backdrop_set_message(t('All aliases for %type have been deleted.', array('%type' => $all_path_info[$key]['label'])));
}
}
else {
// At this point the user want to delete a particular type. We cannot
// be certain for each entity what the source string will look like
// so use a callback per entity.
if (isset($all_path_info[$key]['type delete callback'])) {
$delete_callback = $all_path_info[$key]['type delete callback'];
$delete_callback(array_keys($value));
$delete_list = array();
foreach (array_keys($value) as $type) {
$delete_list[] = $all_path_info[$key]['pattern items'][$type];
}
backdrop_set_message(t('Aliases have been deleted: !type', array('!type' => theme('item_list', array('items' => $delete_list)))));
}
}
}
}
}
$form_state['redirect'] = 'admin/config/urls/path/bulk-update';
}