You are here

function ip_language_negotiation_form in IP Language Negotiation 7

Admin form for the IP Language Negotiation settings.

1 string reference to 'ip_language_negotiation_form'
ip_language_negotiation_menu in ./ip_language_negotiation.module
Implements hook_menu().

File

./ip_language_negotiation.admin.inc, line 11
Admin settings for the IP Language Negotiation.

Code

function ip_language_negotiation_form($form, &$form_state) {
  $countries = country_get_list();
  $languages = locale_language_list();
  $language_default = language_default();
  $settings = variable_get('ip_language_negotiation_countries', array());
  $form['intro'] = array(
    '#markup' => '<p>' . t('Use the interface below to select the default language per country. You only have to set the exceptions, because the default language will be used as fall-back. You can use the <a href="@url">Debug preferences</a> to test the module.', array(
      '@url' => url('admin/config/people/ip2country', array(
        'fragment' => 'edit-ip2country-debug-preferences',
      )),
    )) . '</p>',
  );

  // Remove the default language.
  unset($languages[$language_default->language]);
  $letter = '';
  $default_option = array(
    '' => t('Default (@default_language)', array(
      '@default_language' => $language_default->name,
    )),
  );
  foreach ($countries as $country_code => $country) {

    // Remove accents so we can sort countries correctly.
    $current_letter = iconv('UTF-8', 'ASCII//TRANSLIT', drupal_substr($country, 0, 1));
    if ($letter != $current_letter) {
      $letter = $current_letter;
      if (empty($form['ip_language_letter_' . $letter])) {
        $form['ip_language_letter_' . $letter] = array(
          '#type' => 'fieldset',
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#title' => t('Countries with the letter %letter', array(
            '%letter' => $letter,
          )),
        );
      }
    }
    $form['ip_language_letter_' . $letter][$country_code] = array(
      '#type' => 'radios',
      '#options' => array_merge($default_option, $languages),
      '#title' => $country,
      '#default_value' => '',
    );
    if (!empty($settings[$country_code])) {
      $form['ip_language_letter_' . $letter][$country_code]['#default_value'] = $settings[$country_code];
      $form['ip_language_letter_' . $letter]['#collapsed'] = FALSE;
    }
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}