I was able to set up inbound and outbound alterations in my module using URL alter, but I need the Context module's path condition to trigger based on the unaltered URL.

For instance, if the user enters something like http://my/path/alias/vid/23/view in their browser, URL alter can translate this to http://node/5/vid/23/view, which allows Drupal to display the appropriate page. But if I set up a condition in Context that's supposed to trigger when path=my/path/alias/*, it won't trigger, since Context is also seeing the altered URL

Is there any way to pass the unaltered URL to the Context module?

Comments

jstoller’s picture

Category: support » feature

I was able to work around this issue by adding a few lines to the execute() function in the context_condition_path.inc plugin file. This function now reads:

<?php
  /**
   * Execute.
   */
  function execute() {
    if ($this->condition_used()) {
      // Include both the path alias and normal path for matching.
      $current_path = array(drupal_get_path_alias($_GET['q']));
      if ($current_path != $_GET['q']) {
        $current_path[] = $_GET['q'];
      }
      // Get the original path, if URL Alter was used.
      $browser_path = trim($_SERVER["REQUEST_URI"], '/');
      if ($current_path[0] != $browser_path) {
        $current_path[] = $browser_path;
      }
      foreach ($this->get_contexts() as $context) {
        $paths = $this->fetch_from_context($context, 'values');
        if ($this->match($current_path, $paths, TRUE)) {
          $this->condition_met($context);
        }
      }
    }
  }
?>

As you can see, I am grabbing $_SERVER["REQUEST_URI"] directly and adding it to the list of paths that are checked. I don't know if this is the best approach to this problem, but it seems to be working for me at the moment.

I'm changing this to a feature request. I'd like to see this behavior included as an option in the standard Context path condition.

jstoller’s picture

Sorry. I forgot I was posting to the URL Alter issue queue. I've posted a feature request in the Context issue queue as well, at #1048950: Pass unaltered url to path condition after hook_url_inbound_alter(), for anyone who's interested.

I will let this feature request stand, however, on the off chance there is anything which can be done on the URL Alter side to facilitate this functionality.