You are here

function domain_locale_form_alter in Domain Locale 7

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

Implements hook_form_alter().

  • add validation on language deletion form
  • limit language selection to the enabled languages on domain_conf form
  • allow enabling/disabling languages only for specific domains

File

./domain_locale.module, line 130
Provides domain specific language settings.

Code

function domain_locale_form_alter(&$form, $form_state, $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[t('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;
    case 'locale_languages_overview_form':
      global $_domain;

      // Disable form elements in order to not allow changes from this form, as
      // it would break other domains.
      $form['enabled']['#disabled'] = TRUE;
      $form['site_default']['#disabled'] = TRUE;
      $form['actions']['submit']['#type'] = 'hidden';

      // Build the correct link to where languages are enabled/disabled.
      $link = 'admin/structure/domain/view/' . $_domain['domain_id'] . '/language';

      // Warn admin how to enable/disable for the current domain.
      drupal_set_message(t('By using the module <em>Domain Locale</em> you must set default and enabled languages for each individual domain. Go to the page !link to make changes for this domain. You can still add new languages here.', array(
        '!link' => l($link, $link),
      )), 'warning');
      break;
  }
}