You are here

function domain_locale_form_alter in Domain Locale 6

Same name and namespace in other branches
  1. 7 domain_locale.module \domain_locale_form_alter()

Implementation of hook_form_alter().

File

./domain_locale.module, line 233
domain_locale Domain Locale: manage languages Provides domain specific language settings

Code

function domain_locale_form_alter(&$form, $form_state, $form_id) {

  //echo $form_id;
  switch ($form_id) {
    case 'locale_languages_delete_form':
      $form['#submit'][] = 'domain_locale_languages_delete_submit';
      break;

    //Only allow to select one of the enabled languages as default language
    case 'domain_conf_form':
      $domain_id = $form['domain_id']['#value'];
      $languages = domain_locale_lookup($domain_id);
      if (count($languages) > 0) {
        $default_options = $form[t('Language settings')]['language_default']['#options'];
        $options = $default_options;
        foreach ($default_options as $key => $lang) {
          if (!array_key_exists($key, $languages) && drupal_strlen($key) > 0) {
            unset($options[$key]);
          }
        }
        $form['Language settings']['language_default']['#options'] = $options;
      }
      break;
    case 'domain_batch_form':
      if ($form['batch_item']['#value'] == 'language_default') {
        foreach ($form['domain_batch'] as $key => $value) {
          if (is_int($key)) {
            $languages = domain_locale_lookup($key);
            if (count($languages) > 0) {
              $default_options = $form['domain_batch'][$key]['#options'];
              $options = $default_options;
              foreach ($default_options as $langcode => $language) {
                if (!array_key_exists($langcode, $languages) && drupal_strlen($langcode) > 0) {
                  unset($options[$langcode]);
                }
              }
              $form['domain_batch'][$key]['#options'] = $options;
            }
          }
        }
      }
      break;
  }
}