Hello,
I created a module that hooks to the forms system_site_information_settings. My objective is to store additional fields per domain; the module works ok with one domain however, when I submit the form the values are set equally for all domains. How can I store individual values for each domain? Below is the module I created:

/**
* @filesource
* mysiteinfo.module
*/

function mysiteinfo_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'system_site_information_settings') {
    $form['mysiteinfo_extra_setting2'] = array(
      '#type' => 'textfield',
      '#title' => t('Facebook'),
       '#default_value' => variable_get('mysiteinfo_extra_setting2'),
    );

    $form['mysiteinfo_extra_setting3'] = array(
      '#type' => 'textfield',
      '#title' => t('Twitter'),
    '#default_value' => variable_get('mysiteinfo_extra_setting3'),
    );

    $form['mysiteinfo_extra_setting4'] = array(
      '#type' => 'textfield',
      '#title' => t('Google'),
         '#default_value' => variable_get('mysiteinfo_extra_setting4'),
    );

    $form['mysiteinfo_extra_setting5'] = array(
      '#type' => 'textfield',
      '#title' => t('Pinterest'),
         '#default_value' => variable_get('mysiteinfo_extra_setting5'),
    );
    $form['mysiteinfo_extra_setting6'] = array(
      '#type' => 'textfield',
      '#title' => t('RSS'),
         '#default_value' => variable_get('mysiteinfo_extra_setting6'),
    );
  }

// extra submit form handle
  $form['#submit'][] = 'mysiteinfo_form_submit';
}


// handle form submition 

function mysiteinfo_form_submit($form, &$form_state){
    
    $values = $form_state['values'];
    
    if(!empty($values['mysiteinfo_extra_setting2'])){
        variable_set('mysiteinfo_extra_setting2', $values['mysiteinfo_extra_setting2']);
    }
    
    if(!empty($values['mysiteinfo_extra_setting3'])){
        variable_set('mysiteinfo_extra_setting3', $values['mysiteinfo_extra_setting3']);
    }

    if(!empty($values['mysiteinfo_extra_setting4'])){
        variable_set('mysiteinfo_extra_setting3', $values['mysiteinfo_extra_setting4']);
    }

    if(!empty($values['mysiteinfo_extra_setting5'])){
        variable_set('mysiteinfo_extra_setting3', $values['mysiteinfo_extra_setting5']);
    }

    if(!empty($values['mysiteinfo_extra_setting6'])){
        variable_set('mysiteinfo_extra_setting3', $values['mysiteinfo_extra_setting6']);
    }
}

Comments

agentrickard’s picture

Look in domain.api.php for hook_domain_batch().

joebest’s picture

Since I'm quite new at this, what should be done once I'm there?

agentrickard’s picture

Add all your new variables to a mymodule_domain_batch() function, following the documentation.

See domain_conf_domain_batch() for lots of examples.

joebest’s picture

I really do not how to start. Would it it be much to ask for a step by step way of how to proceed as it was a newbie with zero experience?

Best regards,

agentrickard’s picture

Yes. It would. It's an API function similar to the hook_form_alter() you posted above. It is well-documented, and there are examples.

BTW, you can use system_settings_form() instead of a custom submit handler. See http://api.drupal.org/api/drupal/modules!system!system.module/function/s...

You should also use hook_form_system_site_information_settings_alter() instead of hook_form_alter() for performance (and readability). See http://api.drupal.org/api/drupal/modules!system!system.api.php/function/...

joebest’s picture

Status: Active » Closed (works as designed)

Thanks for the insight.

mikeaskew4’s picture

Using hook_domain_batch() in a custom module, how would one go about making tokens from these custom fields?