diff --git a/modules/path/path.admin.inc b/modules/path/path.admin.inc index 9e22dd70504..d63d26c620e 100644 --- a/modules/path/path.admin.inc +++ b/modules/path/path.admin.inc @@ -95,7 +95,8 @@ function path_admin_form(&$form_state, $edit = array('src' => '', 'dst' => '', ' '#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', @@ -104,7 +105,8 @@ function path_admin_form(&$form_state, $edit = array('src' => '', 'dst' => '', ' '#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( @@ -136,6 +138,10 @@ function path_admin_form_validate($form, &$form_state) { if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE pid != %d AND dst = '%s' AND language = '%s'", $pid, $dst, $language))) { form_set_error('dst', t('The alias %alias is already in use in this language.', array('%alias' => $dst))); } + $item = menu_get_item($src); + if (!$item || !$item['access']) { + form_set_error('src', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $src))); + } } /** @@ -195,18 +201,36 @@ function path_admin_filter_form(&$form_state, $keys = '') { '#maxlength' => 64, '#size' => 25, ); - $form['basic']['inline']['submit'] = array('#type' => 'submit', '#value' => t('Filter')); - + $form['basic']['inline']['submit'] = array( + '#type' => 'submit', + '#value' => t('Filter'), + '#submit' => array('path_admin_filter_form_submit_filter'), + ); + if ($keys) { + $form['basic']['inline']['reset'] = array( + '#type' => 'submit', + '#value' => t('Reset'), + '#submit' => array('path_admin_filter_form_submit_reset'), + ); + } return $form; } /** - * Process filter form submission. + * Process filter form submission when the Filter button is pressed. */ -function path_admin_filter_form_submit($form, &$form_state) { - return 'admin/build/path/list/'. trim($form_state['values']['filter']); +function path_admin_filter_form_submit_filter($form, &$form_state) { + $form_state['redirect'] = 'admin/build/path/list/'. trim($form_state['values']['filter']); } +/** + * Process filter form submission when the Reset button is pressed. + */ +function path_admin_filter_form_submit_reset($form, &$form_state) { + $form_state['redirect'] = 'admin/build/path/list'; +} + + /** * Helper function for grabbing filter keys. */ diff --git a/modules/path/path.module b/modules/path/path.module index 76f81907ca2..f624eb7875a 100644 --- a/modules/path/path.module +++ b/modules/path/path.module @@ -139,18 +139,17 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '' */ 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.')); } break; case 'load': - $path = "node/$node->nid"; - $language = isset($node->language) ? $node->language : ''; + $path = 'node/'. $node->nid; $alias = drupal_get_path_alias($path, $language); if ($path != $alias) { $node->path = $alias; @@ -161,16 +160,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 (isset($node->path)) { - path_set_alias("node/$node->nid", $node->path); + path_set_alias('node/'. $node->nid, $node->path); } 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"; + $path = 'node/'. $node->nid; if (drupal_get_path_alias($path) != $path) { path_set_alias($path); }