Allow alter of domain lookup for dev/stage/prod

Created on 18 December 2013, over 11 years ago
Updated 2 May 2025, about 1 month ago

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

✨ Feature request
Status

Closed: outdated

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States scottalan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024