=== modified file 'modules/path/path.module' --- modules/path/path.module 2007-07-05 08:48:57 +0000 +++ modules/path/path.module 2007-07-07 22:19:19 +0000 @@ -73,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; @@ -89,14 +89,14 @@ function path_admin_edit($pid = 0) { /** * Menu callback; confirms deleting an URL alias **/ -function path_admin_delete_confirm($pid) { +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); - $output = confirm_form($form, - t('Are you sure you want to delete path alias %title?', array('%title' => $path['dst'])), - isset($_GET['destination']) ? $_GET['destination'] : 'admin/build/path'); - } + $form['pid'] = array('#type' => 'value', '#value' => $pid); + $form['path'] = array('#type' => 'value', '#value' => $path); + $output = confirm_form($form, + t('Are you sure you want to delete path alias %alias from path %path?', array('%alias' => $path['dst'], '%path' => $path['src'])), + isset($_GET['destination']) ? $_GET['destination'] : 'admin/build/path'); + return $output; } @@ -105,7 +105,7 @@ function path_admin_delete_confirm($pid) **/ function path_admin_delete_confirm_submit($form, &$form_state) { if ($form_state['values']['confirm']) { - path_admin_delete($form_state['values']['pid']); + path_admin_delete($form_state['values']['pid'], $form_state['values']['path']); $form_state['redirect'] = 'admin/build/path'; return; } @@ -114,9 +114,10 @@ function path_admin_delete_confirm_submi /** * Post-confirmation; delete an URL alias. */ -function path_admin_delete($pid = 0) { +function path_admin_delete($pid = 0, $path) { db_query('DELETE FROM {url_alias} WHERE pid = %d', $pid); - drupal_set_message(t('The alias has been deleted.')); + drupal_clear_path_cache(); + drupal_set_message(t('The alias %alias has been deleted from path %path.', array('%alias' => $path['dst'], '%path' => $path['src']))); } /** @@ -150,19 +151,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(); @@ -185,7 +176,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', @@ -194,7 +186,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( @@ -220,10 +213,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.')); } @@ -231,7 +224,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; @@ -242,12 +234,12 @@ 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': @@ -405,6 +397,9 @@ function path_admin_filter_form(&$form_s '#size' => 25, ); $form['basic']['inline']['submit'] = array('#type' => 'submit', '#value' => t('Filter')); + if ($keys) { + $form['basic']['inline']['reset'] = array('#type' => 'submit', '#value' => t('Reset')); + } return $form; } @@ -413,7 +408,13 @@ function path_admin_filter_form(&$form_s * Process filter form submission. */ function path_admin_filter_form_submit($form, &$form_state) { - return 'admin/build/path/list/'. trim($form_state['values']['filter']); + switch ($form_state['values']['op']) { + case t('Filter'): + $form_state['redirect'] = 'admin/build/path/list/'. trim($form_state['values']['filter']); + break; + default: + $form_state['redirect'] = 'admin/build/path/list/'; + } } /**