I wanted to be able to use Domain Access across environments without having to worry about how it would represent the domain. I wrote a hook_domain_load(), taking ideas from a post by agentrickard. This allows me to set the proper domain in the ui and relay that information to the admin.

I was having trouble however actually finding the correct domain the user is actually on. I'm storing the domains using the 'canonical' domain. I found that when it was trying to lookup the domain it was of course looking for the domain that belongs to the current development/staging site, not the canonical domain that is stored in the db. I wanted to store the canonical domain that is represented by production so that I could allow most of this logic to fall through and not waste processing on prod. By adding a simple drupal_alter in domain_lookup_simple(), I'm able to rewrite the domain for the lookup so that it returns the right domain with the correct domain_id vs the fallback default domain_id.

This worked for me and I realize this may not be the "best" way to handle this. I've stepped through the code quite a bit and it seemed the simplest solution to handle this use case. Let me know if this is way off base or there is a better solution that I'm missing.

I've also included an option for a variable to be set for DOMAIN_INSTALL_RULE instead of having to change the constant in the module. I didn't want to have to do this across environments as I'm building the site using a make file and would have to remember across builds vs just exporting a variable.

$rule_variable = variable_get('domain_install_rule');
$rule = isset($rule_variable) ? $rule_variable : DOMAIN_INSTALL_RULE; 

Thank you,

Scott

CommentFileSizeAuthor
#2 domain_2159443_domain-lookup_1.patch1.02 KBscottalan

Comments

scottalan’s picture

Issue summary: View changes
scottalan’s picture

StatusFileSize
new1.02 KB
agentrickard’s picture

This is usually done in hook_domain_bootstrap_lookup(). See Domain Alias for an example. The use of an alter hook here is a bit fragile, since not all modules will be loaded at this point.

Moving the constant to a variable is a good idea.

bluegeek9’s picture

Status: Active » Closed (outdated)

Drupal 7 in End of Life and no longer supported. We encourage you to upgrade to a supported version of Drupal. For more information, see https://www.drupal.org/upgrade.

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support of this project makes other volunteer contributions more sustainable.
There are multiple ways to show appreciation for the work contributed to this project, including:
  • Triaging issues and adding more context to existing issues.
  • Writing documentation or patches for this project.