I have a numeric value that is unique to each domain (using Domain Access) on my site. I'd like to use the same variable name so I can use the same theme and display this value on all domains. Is this possible?

I'm currently defining the variable in a custom module, but I'm only storing 1 value. Can I alter the code in the custom module so that each domain can have it's own unique value for this variable?


Adding the following when defining the variable in my custom module worked :D

'multidomain' => true,

I can edit the variable through admin/config/system/variable/edit/ and I get unique values across my domains stored in the variable_store table. The problem I now have is that I want to create an admin form for getting/setting a bunch of domain variables and the usual variable_get/variable_set don't work...any thoughts?

3 Answers 3


You must enable "domain configuration" submodule (domain_conf) This will provide you the save per domain option:

function your_module_form($form, &$form_state) {

  $form['variable'] = array(
    '#type' => 'value',
    '#value' => time(),

  return system_settings_form($form);


getting the variable manually:

function domain_conf_variable_get($domain_id, $variable = '', $all = FALSE, $reset = FALSE)

seeting the variable manually:

function domain_conf_variable_set($domain_id, $variable, $value = NULL) 

There is a module which aims to be a replacement variable handling module for Domain Access,If you need setting different variable values for each domain and for each language at the same time you need domain variable module https://drupal.org/project/domain_variable


Another way to do it is with


which gives you a nice settings UI under Domain > Settings

For example, I wrote an implementation of that hook for per-domain apachesolr site hash settings:

* Implements hook_domain_batch().
* Add batch settings to Domain Conf.
function MODULENAME_domain_batch() {

  $batch = array();

    $batch['apachesolr_site_hash'] = array(
      '#form' => array(
        '#title' => t('Apache Solr site hash'),
        '#type' => 'textfield',
        '#description' => t('Unique site hash for Apache Solr.'),
      '#domain_action' => 'domain_conf',
      '#permission' => 'administer site configuration',
      '#system_default' => apachesolr_site_hash(),
      '#meta_description' => t('Set Apache Solr site hash for each domain.'),
      '#variable' => 'apachesolr_site_hash',
      '#data_type' => 'string',
      '#weight' => -1,
      '#group' => t('Apache Solr'),
      '#update_all' => TRUE,
      '#module' => t('Apache Solr'),

  return $batch;


Then you can just use variable_get to retrieve the value on that domain.

  • Can you just use variable_get(), or do you need to use domain_conf_variable_get() as mentioned in Enxebre's answer? Commented Feb 17, 2014 at 20:13
  • You can use variable_get for the current domain value. If you want the value for a different domain, use domain_conf_variable_get Commented Feb 17, 2014 at 22:33

Ok, here is how I solved it...I hope this is the "right" way:

Define the variable, 'multidomain' being the import difference

function MODULENAME_variable_info($options) {

  $variable['social_media_link_twitter'] = array(
    'title' => t('Twitter', array(), $options),
    'description' => t('Twitter URL', array(), $options),
    'type' => 'string',
    'multidomain' => true,
    'access' => 'social media links'

Create a menu to get to the admin form

function MODULENAME_menu() {
  $items = array();

  $items['admin/social-media-links'] = array(
      'title' => t('Social Media Links'),
      'page callback' => 'MODULENAME_social_media_links_admin',
      'access arguments' => array('social media links'),

    return $items;

Menu Page Callback

function MODULENAME_social_media_links_admin() {
  return drupal_get_form('MODULENAME_socialmedialinks_form');

Form Declaration

function MODULENAME_socialmedialinks_form($form_state) {

  /* Just regular old variable_get() */
  $form['social_media_link_twitter'] = array(
    '#title' => t('Twitter'),
    '#type' => 'textfield',
    '#description' => t('Enter your twitter URL. Example: http://twitter.com/SomethingOn'),
    '#default_value' => variable_get('social_media_link_twitter', '')

  /* return the system settings form, not just $form */
  return system_settings_form($form);

Form Submit

function MODULENAME_socialmedialinks_form_submit($form, &$form_state) {

  /* For some reason I have to manually get the domain and set the realm?! */
  $domain = domain_get_domain();
  variable_realm_switch('domain', $domain['subdomain']);

  domain_conf_variable_set($domain['domain_id'], 'social_media_link_twitter', $form_state['values']['social_media_link_twitter']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.