Index: modules/path/path.module =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.module,v retrieving revision 1.125 diff -u -p -r1.125 path.module --- modules/path/path.module 24 Jun 2007 10:09:52 -0000 1.125 +++ modules/path/path.module 26 Jun 2007 23:18:25 -0000 @@ -64,7 +64,6 @@ function path_menu() { 'title' => 'Add alias', 'page callback' => 'drupal_get_form', 'page arguments' => array('path_admin_edit'), - 'access arguments' => array('administer url aliases'), 'type' => MENU_LOCAL_TASK, ); @@ -74,14 +73,14 @@ function path_menu() { /** * Menu callback; handles pages for creating and editing URL aliases. */ -function path_admin_edit($pid = 0) { +function path_admin_edit(&$form_state, $pid = 0) { if ($pid) { $alias = path_load($pid); drupal_set_title(check_plain($alias['dst'])); - $output = path_form($alias); + $output = path_form($form_state, $alias); } else { - $output = path_form(); + $output = path_form($form_state); } return $output; @@ -92,33 +91,25 @@ function path_admin_edit($pid = 0) { **/ function path_admin_delete_confirm(&$form_state, $pid) { $path = path_load($pid); - if (user_access('administer url aliases')) { - $form['pid'] = array('#type' => 'value', '#value' => $pid); - $options = array('cancel' => isset($_GET['destination']) ? $_GET['destination'] : 'admin/build/path'); - $output = confirm_form($form, - t('Are you sure you want to delete path alias %title?', array('%title' => $path['dst'])), - 'admin/build/path', $options); - } - return $output; -} -/** - * Execute URL alias deletion - **/ -function path_admin_delete_confirm_submit($form, &$form_state) { - if ($form_state['values']['confirm']) { - path_admin_delete($form_state['values']['pid']); - $form_state['redirect'] = 'admin/build/path'; - return; - } + drupal_delete_initiate('url_alias', $pid); + drupal_delete_add_query('DELETE FROM {url_alias} WHERE pid = %d', $pid); + drupal_delete_add_callback(array('path_admin_delete_confirm_post' => array($path))); + + return drupal_delete_confirm( + array( + 'question' => t('Are you sure you want to delete path alias %alias from path %path?', array('%alias' => $path['dst'], '%path' => $path['src'])), + 'destination' => 'admin/build/path', + ) + ); } /** - * Post-confirmation; delete an URL alias. + * Post-deletion operations for path alias deletion. */ -function path_admin_delete($pid = 0) { - db_query('DELETE FROM {url_alias} WHERE pid = %d', $pid); - drupal_set_message(t('The alias has been deleted.')); +function path_admin_delete_confirm_post($path) { + drupal_clear_path_cache(); + drupal_set_message(t('The alias %alias has been deleted from path %path.', array('%alias' => $path['dst'], '%path' => $path['src']))); } /** @@ -127,12 +118,9 @@ function path_admin_delete($pid = 0) { function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '') { if ($path && !$alias) { // Delete based on path + drupal_delete_initiate('url_alias', $path); drupal_delete_add_query("DELETE FROM {url_alias} WHERE src = '%s' AND language = '%s'", $path, $language); - drupal_clear_path_cache(); - } - else if (!$path && $alias) { - // Delete based on alias - drupal_delete_add_query("DELETE FROM {url_alias} WHERE dst = '%s' AND language = '%s'", $alias, $language); + drupal_delete_execute(); drupal_clear_path_cache(); } else if ($path && $alias) { @@ -152,19 +140,9 @@ function path_set_alias($path = NULL, $a db_query("INSERT INTO {url_alias} (src, dst, language) VALUES ('%s', '%s', '%s')", $path, $alias, $language); } } - // The alias exists. + // The alias exists, update the path. else { - // This path has no alias yet, so we redirect the alias here. - if ($path_count == 0) { - db_query("UPDATE {url_alias} SET src = '%s' WHERE dst = '%s' AND language = '%s'", $path, $alias, $language); - } - else { - // This will delete the path that alias was originally pointing to. - path_set_alias(NULL, $alias, NULL, $language); - // This will remove the current aliases of the path. - path_set_alias($path, NULL, NULL, $language); - path_set_alias($path, $alias, NULL, $language); - } + db_query("UPDATE {url_alias} SET src = '%s' WHERE dst = '%s' AND language = '%s'", $path, $alias, $language); } if ($alias_count == 0 || $path_count == 0) { drupal_clear_path_cache(); @@ -187,7 +165,8 @@ function path_form(&$form_state, $edit = '#maxlength' => 64, '#size' => 45, '#description' => t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1+2.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=') + '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), + '#required' => TRUE, ); $form['dst'] = array( '#type' => 'textfield', @@ -196,7 +175,8 @@ function path_form(&$form_state, $edit = '#maxlength' => 64, '#size' => 45, '#description' => t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=') + '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), + '#required' => TRUE, ); // This will be a hidden value unless locale module is enabled $form['language'] = array( @@ -222,10 +202,10 @@ function path_form(&$form_state, $edit = */ function path_nodeapi(&$node, $op, $arg) { if (user_access('create url aliases') || user_access('administer url aliases')) { + $language = isset($node->language) ? $node->language : ''; switch ($op) { case 'validate': $node->path = trim($node->path); - $language = isset($node->language) ? $node->language : ''; if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s' AND language = '%s'", $node->path, "node/$node->nid", $language))) { form_set_error('path', t('The path is already in use.')); } @@ -233,7 +213,6 @@ function path_nodeapi(&$node, $op, $arg) case 'load': $path = "node/$node->nid"; - $language = isset($node->language) ? $node->language : ''; $alias = drupal_get_path_alias($path, $language); if ($path != $alias) { $node->path = $alias; @@ -244,19 +223,16 @@ function path_nodeapi(&$node, $op, $arg) // Don't try to insert if path is NULL. We may have already set // the alias ahead of time. if ($node->path) { - path_set_alias("node/$node->nid", $node->path); + path_set_alias("node/$node->nid", $node->path, NULL, $language); } break; case 'update': - path_set_alias("node/$node->nid", isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL); + path_set_alias("node/$node->nid", isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL, $language); break; case 'delete': - $path = "node/$node->nid"; - if (drupal_get_path_alias($path) != $path) { - path_set_alias($path); - } + drupal_delete_add_query("DELETE FROM {url_alias} WHERE src = '%s'", "node/$node->nid"); break; } }