Is it possible to set a "domain name" which is different to the "site name"? (i.e. basically give each domain a custom label?)

I have a website for a company with 3 subsidiaries in 4 different countries; I use different domains for each of them, and usually set the "site name" to be the (legal) name of the respective company/subsidiary. In order to make it easier for admins (during content creation) and also users (domain switcher), I would like to label each domain by it's country...

Is this possible somehow? Custom module workarounds would be fine...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agentrickard’s picture

Use hook_domain_load() to change the name of the domain if you like. Or use hook_node_form_alter() in a module that runs _after_ domain.

bforchhammer’s picture

Hm, if I override the domain name via hook_domain_load then the site name is also affected (because it is set in domain_init)... I'm going to try using hook_node_form_alter (and other hooks for other places); was just hoping there might be an easier way ;-)

bforchhammer’s picture

Status: Active » Fixed

I ended up changing the domain name, and overriding $conf['site_name'] in hook_init() with custom site names (company names, in my case).

// MYMODULE.module
function MYMODULE_init() {
  global $conf;
  $domain = domain_get_domain();
  drupal_alter('site_name', $conf['site_name'], $domain['machine_name']);
}

// MYMODULE_DE.module
function MYMODULE_DE_site_name_alter(&$name, $domain) {
  if ($domain == 'de_mydomain_com') $name = 'German Company Name';
}

// MYMODULE_CH.module
function MYMODULE_CH_site_name_alter(&$name, $domain) {
  if ($domain == 'ch_mydomain_com') $name = 'Swiss Company Name';
}

agentrickard’s picture

Category: support » feature
Status: Fixed » Active

For those following along, this will only work if your module's hook_init() fires after domain_init().

Perhaps we should put that alter hook into domain_init()?

bforchhammer’s picture

this will only work if your module's hook_init() fires after domain_init().

Right, I have also set the module's weight value to 1 to ensure that that's the case... :-)

Perhaps we should put that alter hook into domain_init()?

Sure, why not. Patch attached... (api) docs still missing.

Alternatively I'm wondering whether it might be possible to completely remove that line ( $conf['site_name'] = ...), and expose the site_name variable via domain_conf? Or possibly with an option to fall back to the "domain sitename" (enabled by default?).

agentrickard’s picture

That line is a legacy from the very early days (D5), and I'd hate to remove the behavior now. It does, however, cause issues for i18n folks, so I'd love to get some input.

bforchhammer’s picture

Maybe something like this?

Attached patch makes the "sitename overridding" optional, adds a respective checkbox to the module settings page, and adds "site_name" variable into domain_conf forms. For existing users behavior should remain the same...

agentrickard’s picture

As much as I hate adding new setting at this point, we have taken a similar approach to other changes.

My remaining question is: does this allow i18n to act more effectively?

bforchhammer’s picture

My remaining question is: does this allow i18n to act more effectively?

I am not sure... I haven't used "i18n + domain" since D6; it's on my agenda for a current project, but it may still be a little while until I get to it. I'm also looking #1307058: Use new Variable API for different variables per domain. on that topic... I guess if the "variable realms" stuff is working then it would also apply to the site_name variable, thus making it easier to translate the site name. Hm.

bforchhammer’s picture

Status: Active » Needs review
FileSize
3.98 KB

After working on the domain+i18n+variable integration, I can say: yes, this will definitely help with i18n...

Assuming that a domain_variable module is "the future", anyway. With the override turned off, the sitename is treated like any other variable and can therefore be translated using i18n_variable. Of course, we will still have to solve the domain+i18n variable integration, before it's possible to have proper multilingual sitenames for different domains.

Either way, I think this is a step into the right direction.

Attached is an updated patch... (last one did not remove the site-information form submit handler when the override was disabled).

agentrickard’s picture

Status: Needs review » Needs work

Looks right. We need to whip up a simple test for it.

bforchhammer’s picture

Version: 7.x-3.3 » 7.x-3.x-dev
Status: Needs work » Needs review
FileSize
7.78 KB
3.8 KB

Attached is the same patch with some tests...

bforchhammer’s picture

This patch will be required for building multilingual site names with the domain_variable module. See also #1593558: Support site_name variable.

lolandese’s picture

Works!

Steps followed:

  • patch -p1 < sitename-override-1550762-12.patch in /public_html/drupal-7.14/sites/all/modules/domain
  • Turn off "Override site name with name of domain" at admin/structure/domain/settings.
  • Enable the modules Variable admin and Variable realm admin. For the translation of site-slogans per domain this was not necessary (out of curiosity: is site slogan set by default for the domain realm as it's a variable that you probably want to differ between domains?).
  • At admin/config/system/variable/realm/domain/configure select "Site name".
  • At admin/config/regional/i18n/variable select "Site name". (I think I've found it selected already).
  • Set a different site name per language per domain at admin/config/system/site-information and voilà. Done!

Going to admin/structure/domain/view/1/variables I find "Site name: Drupal" and "Site slogan: <empty>". I guess this is inevitable for now but a small inconsistency in the UI.

Thanks. Great job.

bforchhammer’s picture

Is site slogan set by default for the domain realm as it's a variable that you probably want to differ between domains?.

No, at the moment no variables are selected by default... you have to enable the slogan manually. We may have to change that eventually, and this will definitely be a required step for #1593548: Migration path from domain_conf.

Going to admin/structure/domain/view/1/variables I find "Site name: Drupal" and "Site slogan: ". I guess this is inevitable for now but a small inconsistency in the UI.

The domain variables page should actually show the same values as set on the site-information form (for the respective domain and active language that is); if that's not the case that's likely a bug in variable_realm or domain_variable... (-> separate issue)

Both issues are independent from this issue+patch.

agentrickard’s picture

Some cleanups here. A few are just text strings. There was some inconsistency in naming. Fixed a form weight issue and an uninstall hook.

Could use a last sanity check. Tests all pass.

bforchhammer’s picture

Status: Needs review » Reviewed & tested by the community

Patch still applies and looks fine :)

agentrickard’s picture

Status: Reviewed & tested by the community » Fixed

Committed. 8cdd2f7..3975188

Needs a documentation fix: https://drupal.org/node/1096974

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dark_kz’s picture

Tried your manual, but no result http://drupal.org/node/1848864 :(