1 locale.inc locale_language_switcher_session($type, $path)

Return the session language switcher block.

Related topics

File

core/includes/locale.inc, line 381
Administration functions for locale.module.

Code

function locale_language_switcher_session($type, $path) {
  backdrop_add_css(backdrop_get_path('module', 'locale') . '/css/locale.css');

  $param = config_get('locale.settings', 'language_negotiation_session_parameter');
  $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : $GLOBALS[$type]->langcode;

  // Get the enabled languages only.
  $language_list = language_list(TRUE, TRUE, TRUE);
  $links = array();

  $query = $_GET;
  unset($query['q']);

  foreach ($language_list as $langcode => $label) {
    $links[$langcode] = array(
      'href' => $path,
      'title' => $label,
      'attributes' => array('class' => array('language-link')),
      'query' => $query,
    );
    if ($language_query != $langcode) {
      $links[$langcode]['query'][$param] = $langcode;
    }
    else {
      $links[$langcode]['attributes']['class'][] = 'session-active';
    }
  }

  return $links;
}