You are here

function language_cookie_language_switcher in Language Cookie 7

Same name and namespace in other branches
  1. 7.2 language_cookie.module \language_cookie_language_switcher()

Return the cookie language switcher block.

1 string reference to 'language_cookie_language_switcher'
language_cookie_language_negotiation_info in ./language_cookie.module
Implements hook_language_negotiation_info().

File

./language_cookie.module, line 136
Language Cookie module.

Code

function language_cookie_language_switcher($type, $path) {

  // No need to modify the language switcher if LOCALE_LANGUAGE_NEGOTIATION_URL
  // already takes care of it for us.
  require_once DRUPAL_ROOT . '/includes/locale.inc';
  if (language_negotiation_get_any(LOCALE_LANGUAGE_NEGOTIATION_URL)) {
    return array();
  }
  drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');
  $param = variable_get('language_cookie_param', 'language');
  $language_query = isset($_COOKIE[$param]) ? $_COOKIE[$param] : $GLOBALS[$type]->language;
  $languages = language_list('enabled');
  $links = array();
  $query = $_GET;
  unset($query['q']);
  foreach ($languages[1] as $language) {
    $langcode = $language->language;
    $links[$langcode] = array(
      'href' => $path,
      'title' => $language->native,
      'attributes' => array(
        'class' => array(
          'language-link',
        ),
      ),
      'query' => $query,
    );
    if ($language_query != $langcode) {
      $links[$langcode]['query'][$param] = $langcode;
    }
    else {
      $links[$langcode]['attributes']['class'][] = ' session-active';
      $links[$langcode]['attributes']['class'][] = ' cookie-active';
    }
  }
  return $links;
}