You are here

language_selection_page.admin.inc in Language Selection Page 6

The admin page of the language selection page module.

File

language_selection_page.admin.inc
View source
<?php

/**
 * @file
 * The admin page of the language selection page module.
 */

/**
 * The admin page form.
 *
 * @return array
 */
function language_selection_page_admin() {
  module_load_include('inc', 'language_selection_page', 'includes/language_selection_page.helpers');
  $form = array();
  $error = FALSE;
  $language_count = _language_selection_page_check_language_count();
  if ($language_count['db'] != $language_count['vars']) {
    drupal_set_message(_language_selection_page_get_error_messages('language_count', $language_count['db'], $language_count['vars']), 'error');
    return $form;
  }
  if (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) != 2) {
    drupal_set_message(_language_selection_page_get_error_messages('language_negotiation', t('Language negotiation'), t('Path prefix with language fallback.'), url('admin/settings/language/configure')), 'warning');
    $error = TRUE;
  }
  if ($language_count['db'] < 2) {
    drupal_set_message(_language_selection_page_get_error_messages('language_enabled', url('admin/settings/language')), 'warning');
    $error = TRUE;
  }
  if ($error) {
    return $form;
  }
  $lang_list = language_list('enabled');
  foreach ($lang_list[1] as $lang) {
    if (empty($lang->prefix)) {
      drupal_set_message(_language_selection_page_get_error_messages('language_prefix', url('admin/settings/language/edit/' . $lang->language), $lang->name), 'warning');
    }
  }
  $options = array(
    '1' => t('No but redirect if language is found from cookie.'),
    '2' => t('No'),
    '4' => t('Yes'),
  );
  $form['language_selection_page_enable'] = array(
    '#title' => t('Redirect to a language selection page if no language is detected from URL and/or Cookie ?'),
    '#type' => 'radios',
    '#default_value' => variable_get('language_selection_page_enable', 2),
    '#options' => $options,
    '#description' => t('Select yes if you want to enable the Language Selection Page when no language is detected from URL and/or Cookie.'),
  );
  $options = array(
    '8' => t('No'),
    '16' => t('Yes'),
  );
  $form['language_selection_page_use_language_cookie'] = array(
    '#title' => t('Use a cookie to remember your language ?'),
    '#type' => 'radios',
    '#default_value' => variable_get('language_selection_page_use_language_cookie', 8),
    '#options' => $options,
    '#description' => t('Select yes if you want to store the language in a cookie.<br/>The cookie is <i>%cookie</i>.', array(
      '%cookie' => LANGUAGE_SELECTION_PAGE_LANGUAGE_COOKIE_KEY,
    )),
  );
  $form['language_selection_page_language_url_argument'] = array(
    '#type' => 'textfield',
    '#title' => t('Language URL argument'),
    '#default_value' => variable_get('language_selection_page_language_url_argument', ''),
    '#size' => 15,
    '#description' => t('If this is set, the module will also check for a url argument.<br/>' . 'If that argument is found and validated, it will be used as language.<br/>' . 'Set this variable to empty to disable the behavior.'),
  );
  $options = array(
    '32' => t('Template in theme'),
    '64' => 'Template only',
  );
  $form['language_selection_page_redirect_type'] = array(
    '#title' => t('Select the way the Selection Page should work'),
    '#type' => 'select',
    '#multiple' => FALSE,
    '#default_value' => variable_get('language_selection_page_redirect_type', 64),
    '#options' => $options,
    '#description' => t('<b>Template in theme</b>: Insert the Language Selection Page body as <i>$content</i> in the current theme.
                         <br/><b>Template only</b>: Display the Language Selection Page template only.
                         <br/>Create a file named <i>language_selection_page.tpl.php</i> in your theme directory if you want to override the full page.
                         <br/>Create a file named <i>language_selection_page_body.tpl.php</i> in your theme directory if you want to override the body only.'),
  );
  $form['language_selection_page_blacklisted_paths'] = array(
    '#type' => 'textarea',
    '#title' => t('List of paths to blacklist'),
    '#default_value' => implode("\n", variable_get('language_selection_page_blacklisted_paths', array(
      'admin',
      'user',
      'admin/*',
      'admin*',
      'node/add/*',
      'node/*/edit',
    ))),
    '#size' => 10,
    '#description' => t('Write on each line a path to blacklist from Language Selection Page processor'),
  );
  $form['language_selection_page_cookie_lifetime'] = array(
    '#type' => 'textfield',
    '#field_suffix' => t('Seconds'),
    '#title' => t('Cookie lifetime'),
    '#default_value' => variable_get('language_selection_page_cookie_lifetime', 2592000),
    '#size' => 10,
    '#description' => t('Cookie lifetime, must be greater than zero. (2592000 = 1 month)'),
  );
  $form['#submit'][] = 'language_selection_page_admin_submit';
  return system_settings_form($form);
}

/**
 * Implementation of the hook_form_validate().
 */
function language_selection_page_admin_validate($form, &$form_state) {
  $form_state['values']['language_selection_page_blacklisted_paths'] = explode("\n", trim($form_state['values']['language_selection_page_blacklisted_paths']));
  if ($form_state['values']['language_selection_page_enable'] == 1 && $form_state['values']['language_selection_page_use_language_cookie'] == 8) {
    form_set_error('language_selection_page_use_language_cookie', t('Enable cookie if you want to use cookie.'));
  }
  if ($form_state['values']['language_selection_page_cookie_lifetime'] <= 0) {
    form_set_error('language_selection_page_cookie_lifetime', t('The cookie lifetime must be greater than zero.'));
  }
}

/**
 * Implementation of the hook_form_submit().
 */
function language_selection_page_admin_submit($form, &$form_state) {
  if ($form_state['values']['language_selection_page_use_language_cookie'] == 8) {
    setcookie(LANGUAGE_SELECTION_PAGE_LANGUAGE_COOKIE_KEY, NULL, 0, '/');
    drupal_set_message(t('Language Selection Page Cookie removed.'));
  }
}

Functions

Namesort descending Description
language_selection_page_admin The admin page form.
language_selection_page_admin_submit Implementation of the hook_form_submit().
language_selection_page_admin_validate Implementation of the hook_form_validate().