You are here

function context_prefix_goto in Context 5

A wrapper around drupal_goto() that abstracts out the prefix/context setting You provide both a normal drupal path ('node/43') and a context prefix ('dsi') and context_prefix_goto will determine the correct location to use.

File

context_prefix/context_prefix.module, line 607

Code

function context_prefix_goto($provider, $id, $path = '', $query = NULL, $fragment = NULL, $http_response_code = 302) {

  /**
   * TODO: we need to abstract this base_url dissection into a
   * handler, and in there, we'll abstract out for
   * protocol handling, and handling the site's base_url like www.
   *
   * TODO: we need to make sure that other prefixed contexts don't
   * get dropped. e.g. if you are on 'en/node/43' and you
   * context_prefix_goto('spaces', 'mygroup'), you should end up
   * at 'en/mygroup', not 'mygroup'
   */
  $method = variable_get('context_prefix_method_' . $provider, CONTEXT_PREFIX_PATH);
  $prefixes = context_prefix_prefixes($method);
  switch ($method) {
    case CONTEXT_PREFIX_PATH:
      foreach ($prefixes as $key => $info) {
        if ($info['id'] == $id) {
          clswitch('set', true);

          // Drop prefixing for context_prefix goto's
          $path = $key . '/' . $path;
          break;
        }
      }
      break;
    case CONTEXT_PREFIX_PAIR:
      clswitch('set', true);
      $prefixes = array_keys($prefixes);
      $path = $prefixes[0] . '/' . $id . '/' . $path;
      break;
    case CONTEXT_PREFIX_DOMAIN:
      foreach ($prefixes as $key => $info) {
        if ($info['id'] == $id) {
          $path = 'http://' . $key . '/' . $path;
          break;
        }
      }
      break;
  }
  drupal_goto($path, $query, $fragment, $http_response_code);
}