You are here

function globallink_locale in GlobalLink Connect for Drupal 7.7

Same name and namespace in other branches
  1. 7.5 globallink_locale_mapping.inc \globallink_locale()
  2. 7.6 globallink_locale_mapping.inc \globallink_locale()

Renders form for globallink_locale.

2 string references to 'globallink_locale'
export_csv_button_submit in ./globallink_settings.inc
Export csv batch set.
globallink_locale_page in ./globallink_locale_mapping.inc
Returns form for globallink_locale page.

File

./globallink_locale_mapping.inc, line 19
Globallink_locale_mapping.inc is a file that contains most functions needed on the Locale Mapping UI.

Code

function globallink_locale() {
  $form = array();
  $languages = language_list('language', TRUE);
  $mapped_languages = globallink_get_mapped_locale_codes();
  if (sizeof($mapped_languages) > 0) {
    foreach ($mapped_languages as $mlang) {
      foreach ($languages as $language) {
        if ($language->language == $mlang) {
          unset($languages[$mlang]);
          break;
        }
      }
    }
  }
  $drupal_list = array();
  foreach ($languages as $language) {
    if ($language->enabled == 1) {
      $drupal_list[$language->language . '|' . $language->name] = $language->name;
    }
  }
  $tpt_list = globallink_get_tpt_list();
  $header = array(
    'drupal_locale_code' => array(
      'field' => 'tl.drupal_locale_desc',
      'data' => t('Drupal Site Locales'),
    ),
    'locale_code' => array(
      'field' => 'tl.locale_desc',
      'data' => t('GlobalLink Locales'),
    ),
  );
  $query = db_select('globallink_locale', 'tl')
    ->isNotNull('drupal_locale_code')
    ->fields('tl')
    ->extend('PagerDefault')
    ->limit(TPT_PAGER_LIMIT)
    ->extend('TableSort')
    ->orderByHeader($header);
  $results = $query
    ->execute();
  $count = 0;
  $rows = array();
  foreach ($results as $item) {
    $count++;
    $rows[$item->locale_code] = array(
      'drupal_locale_code' => $item->drupal_locale_desc,
      'locale_code' => $item->locale_desc,
    );
  }
  $form['table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#empty' => t('No items available'),
  );
  $form['pager'] = array(
    '#markup' => theme('pager'),
  );
  if ($count > 0) {
    $form['submit_locale_delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
  }
  $form['locale_mapping'] = array(
    '#title' => t('Locale Mapping'),
    '#type' => 'fieldset',
    '#description' => t('Map the Drupal locales with GlobalLink locales'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  if (sizeof($drupal_list) > 0) {
    $form['locale_mapping']['drupal_locale_list'] = array(
      '#title' => t('Drupal Locale'),
      '#type' => 'select',
      '#options' => $drupal_list,
    );
    $form['locale_mapping']['tpt_locale_list'] = array(
      '#title' => t('GlobalLink Locale'),
      '#type' => 'select',
      '#options' => $tpt_list,
    );
    $form['locale_mapping']['submit_locale_add'] = array(
      '#type' => 'submit',
      '#value' => t('Add'),
    );
  }
  else {
    $form['locale_mapping']['no_mapping'] = array(
      '#type' => 'markup',
      '#prefix' => '<br/><b><i>',
      '#markup' => t('Nothing to Map'),
      '#suffix' => '</i></b>',
    );
  }
  return $form;
}