You are here

function rules_action_drupal_goto in Rules 6

Same name and namespace in other branches
  1. 7.2 modules/system.eval.inc \rules_action_drupal_goto()

Action Implementation: Page redirect.

Related topics

File

rules/modules/system.rules.inc, line 170
rules integration for the system module

Code

function rules_action_drupal_goto($settings) {

  // For settings backward compatibility respect the override setting as default
  $settings += array(
    'immediate' => isset($settings['override']) && !$settings['override'],
  );
  extract($settings);
  if ($force) {
    if (strpos($query, 'destination') === FALSE) {
      if (!empty($query)) {
        $query .= '&';
      }

      // Keep the current destination parameter if there is one.
      $query .= isset($_REQUEST['destination']) ? 'destination=' . urlencode($_REQUEST['destination']) : NULL;
    }
    unset($_REQUEST['destination']);
  }
  if ($immediate) {
    drupal_goto($path, $query ? $query : NULL, $fragment ? $fragment : NULL);
  }
  else {

    // If someone else issues a drupal_goto(), we hijack it by setting the destination parameter
    // But obey any already set destination parameter.
    if (!isset($_REQUEST['destination'])) {
      $_REQUEST['destination'] = urlencode($path) . ($query ? '?' . urlencode($query) : '') . ($fragment ? '#' . urlencode($fragment) : '');
    }

    // This lets _rules_action_drupal_goto_handler() invoke drupal_goto before the page is output.
    $GLOBALS['_rules_action_drupal_goto_do'] = TRUE;
  }
}