diff -u b/redirect.admin.inc b/redirect.admin.inc --- b/redirect.admin.inc +++ b/redirect.admin.inc @@ -367,12 +367,6 @@ '#description' => t('Enter an internal Drupal path, path alias, or complete external URL (like http://example.com/) to redirect to. Use %front to redirect to the front page.', array('%front' => '')), '#element_validate' => array('redirect_element_validate_redirect'), ); - $form['status'] = array( - '#type' => 'checkbox', - '#title' => t('Enabled'), - '#default_value' => $redirect->status, - '#required' => FALSE, - ); $form['redirect_options'] = array( '#type' => 'value', @@ -386,6 +380,14 @@ '#value' => $redirect->language, ); + $form['status'] = array( + '#type' => 'checkbox', + '#title' => t('Enabled'), + '#description' => t('If this box is checked, this redirect will be enabled.'), + '#default_value' => $redirect->status, + '#required' => FALSE, + ); + $form['advanced'] = array( '#type' => 'fieldset', '#title' => t('Advanced options'), @@ -533,10 +535,12 @@ $redirect = (object) $form_state['values']; if (empty($form_state['values']['override'])) { - if ($existing = redirect_load_by_source($redirect->source, $redirect->language)) { + // Find out if any (disabled or enabled) redirect with this source already exists. + if ($existing = redirect_load_by_source($redirect->source, $redirect_language, array(), FALSE)) { if ($redirect->rid != $existing->rid && $redirect->language == $existing->language) { - // The "from" path should not conflict with another redirect - $form_state['storage']['override_messages']['redirect-conflict'] = t('The base source path %source is already being redirected. Do you want to edit the existing redirect?', array('%source' => $redirect->source, '@edit-page' => url('admin/config/search/redirect/edit/'. $existing->rid))); + // The "from" path should not conflict with another (disabled or + // enabled) redirect. + $form_state['storage']['override_messages']['redirect-conflict'] = t('A redirect already exists for the source path %source. Do you want to edit the existing redirect?', array('%source' => $redirect->source, '@edit-page' => url('admin/config/search/redirect/edit/'. $existing->rid))); $form_state['rebuild'] = TRUE; } } diff -u b/redirect.module b/redirect.module --- b/redirect.module +++ b/redirect.module @@ -541,6 +541,9 @@ * @param $source * The source of the URL redirect. * + * @param $enabled_only + * Boolean that indicates whether to only load enabled redirects. + * * @return * An array of URL redirect objects indexed by redirect IDs. * @@ -550,11 +553,13 @@ * * @ingroup redirect_api */ -function redirect_load_by_source($source, $language = LANGUAGE_NONE, array $query = array()) { +function redirect_load_by_source($source, $language = LANGUAGE_NONE, array $query = array(), $enabled_only = TRUE) { // Run a case-insensitive query for matching RIDs first. $rid_query = db_select('redirect'); $rid_query->addField('redirect', 'rid'); - $rid_query->condition('status', 1); + if ($enabled_only) { + $rid_query->condition('status', 1); + } if ($source != variable_get('site_frontpage', 'node')) { $rid_query->condition('source', db_like($source), 'LIKE'); } @@ -695,7 +700,7 @@ redirect_hash($redirect); if ($existing = redirect_load_by_hash($redirect->hash)) { if ($redirect->rid != $existing->rid) { - form_set_error('source', t('The source path %source is already being redirected. Do you want to edit the existing redirect?', array('%source' => redirect_url($redirect->source, $redirect->source_options), '@edit-page' => url('admin/config/search/redirect/edit/'. $existing->rid)))); + form_set_error('source', t('A redirect already exists for the source path %source. Do you want to edit the existing redirect?', array('%source' => redirect_url($redirect->source, $redirect->source_options), '@edit-page' => url('admin/config/search/redirect/edit/'. $existing->rid)))); } } @@ -1569,7 +1574,7 @@ // We don't have to put our include in $form_state['build_info']['files'] // since the build array will already be cached. module_load_include('inc', 'redirect', 'redirect.admin'); - $redirects = redirect_load_multiple(FALSE, array('redirect' => $uri['path'])); + $redirects = redirect_load_multiple(FALSE, array('redirect' => $uri['path'], 'status' => 1)); $header = array('source', 'status_code', 'language', 'count', 'access', 'operations'); $form['redirect'] += redirect_list_table($redirects, $header); } diff -u b/redirect.test b/redirect.test --- b/redirect.test +++ b/redirect.test @@ -230,20 +230,20 @@ // Change the node's alias will create an automatic redirect from 'first-alias' to the node. $this->drupalPost("node/{$node->nid}/edit", array('path[alias]' => 'second-alias'), 'Save'); - //$redirect = redirect_load_by_source('first-alias'); - //$this->assertRedirect($redirect); + $this->drupalGet('first-alias'); + $this->assertText($node->title); $this->drupalPost("node/{$node->nid}/edit", array('path[alias]' => 'first-alias'), 'Save'); $this->assertResponse(200, "Changing node's alias back to 'first-alias' does not break page load with a circular redirect."); $this->assertNoText('Infinite redirect loop prevented.'); - //$redirect = redirect_load_by_source('second-alias'); - //$this->assertRedirect($redirect); + $this->drupalGet('second-alias'); + $this->assertText($node->title); $this->drupalPost("node/{$node->nid}/edit", array('path[alias]' => 'second-alias'), 'Save'); $this->assertResponse(200, "Changing node's alias back to 'second-alias' does not break page load with a circular redirect."); $this->assertNoText('Infinite redirect loop prevented.'); - //$redirect = redirect_load_by_source('first-alias'); - //$this->assertRedirect($redirect); + // Note at this point the first-alias redirect has already been disabled, so + // going to first-alias will give a 404 error. } function testPathAddOverwriteRedirects() {