I've found an issue when placing content via path-pased rules. For instance, if I place a block to appear on certain pages, using either the core Drupal block admin UI, or Context, the blocks do not appear on pages where Domain Path determines the path/page.

I've got 3 domains, and each has an "About us" page, which is a standard node.
example.com/about-us -> node/100
one.example.com/about-us -> node/101
two.example.com/about-us -> node/102
node/100 has a Drupal alias for 'about-us' while the other nodes use Domain Path to set their domain-specific aliases to 'about-us'.

I've created a block with Views of links to other nodes (each domain has plenty of nodes that show up in this view). However, when I place a block on certain pages using the admin UI and set 'Show block on specific pages' to 'about-us' and 'about-us/*', only the primary domain displays the block on the about-us page. I've also tried to place this block using Context and a path-based trigger, but I still don't get the block on the subdomains' pages.

As best as I can determine, this is because the domain with the *actual* alias of 'about-us' triggers the rule. The Domain Path module uses hook_url_inbound_alter which sets the active path to the cononical path, which would be node/NID. If I use 'node/*' in the block configuration it shows up fine.

Comments

agentrickard’s picture

Status: Active » Closed (won't fix)

Correct and not fixable. This is a trade off for having domain-specific paths.

There is a potential feature request here for setting Context conditions properly, but the core path-lookups are hard-wired and cannot, AFAIK, be overridden.

eric.chenchao’s picture

Issue summary: View changes

It might be helpful to anyone who also got this issue.

The idea is to write a custom context path plugin

Here is the code

Define plugin in the mymodule.module


/**
 * Implements hook_context_plugin().
 */
function mymodule_context_plugins() {
    $plugins = array();
    $plugins['context_mymodule_path'] = array(
        'handler' => array(
            'path' => drupal_get_path('module', 'mymodule') .'/plugins',
            'file' => 'context_mymodule_path.inc',
            'class' => 'context_mymodule_path',
            'parent' => 'context_condition',
        ),
    );

    return $plugins;
}

/**
 * Implements hook_context_registry().
 */
function mymodule_context_registry() {
    $registry = array();

    $registry['conditions'] = array(
        'mymodule_path' => array(
            'title' => t('Compatible Path'),
            'description' => t('Make this path condition compatible with domain_path'),
            'plugin' => 'context_mymodule_path',
        ),
    );

    return $registry;
}

Save this code to mymodule/plugins/context_mymodule_path.inc

class context_mymodule_path extends context_condition_path {

    /**
     * Execute.
     */
    function execute() {
        if ($this->condition_used()) {
            // Include both the path alias and normal path for matching.
            $current_path = array($_GET['q']);

            $path_alias = drupal_get_path_alias($_GET['q']);

            if ($path_alias == $_GET['q'] && module_exists('domain_path')) {
                $path_alias = domain_path_lookup_path('alias', $_GET['q']);
            }

            // $path_alias can be false.
            if ($path_alias && $path_alias != $_GET['q']) {
                $current_path[] = $path_alias;
            }

            foreach ($this->get_contexts() as $context) {
                $paths = $this->fetch_from_context($context, 'values');
                if ($this->match($current_path, $paths, TRUE)) {
                    $this->condition_met($context);
                }
            }
        }
    }
}

And set the trigger in the mymodule.module

/**
 * Implementation of hook_init().
 */
function mymodule_init() {
    if ($plugin = context_get_plugin('condition', 'mymodule_path')) {
        $plugin->execute();
    }
}