Commit 61448e52 authored by Aaron Wells's avatar Aaron Wells
Browse files

Bug 1597957: Handle language select form on non-public pages

By moving the language select form's handler into
a Pieforms submit method, we ensure that the form
can be properly handled on any page that displays it.

behatnotneeded: Can't test multi-language with behat yet

Change-Id: I04aea40b9ba1000f75fc08ef7015fd00de3bc9da
parent 4aab2c06
......@@ -507,9 +507,6 @@ function auth_setup () {
// Check if the page is public or the site is configured to be public.
if (defined('PUBLIC') && !isset($_GET['login'])) {
if ($lang = param_alphanumext('lang', null)) {
$SESSION->set('lang', $lang);
}
return;
}
......
......@@ -4374,7 +4374,8 @@ function mahara_shorturl_request($url, $quiet=false) {
}
/**
* Returns a language select form
* Generates the language selection form, for logged-out users.
* (And though Pieform magic, also handles submission of that form.)
*
* @return string HTML of language select form
*/
......@@ -4393,8 +4394,7 @@ function language_select_form() {
'name' => 'languageselect',
'renderer' => 'div',
'class' => 'form-inline with-label-widthauto',
'validate' => false,
'presubmitcallback' => '',
'successcallback' => 'language_select_form_submit',
'elements' => array(
'inputgroup' => array(
'type' => 'fieldset',
......@@ -4406,6 +4406,7 @@ function language_select_form() {
'hiddenlabel' => true,
'options' => $languages,
'defaultvalue' => $SESSION->get('lang') ? $SESSION->get('lang') : 'default',
'rules' => array('required' => true),
),
'changelang' => array(
'type' => 'button',
......@@ -4421,6 +4422,20 @@ function language_select_form() {
return $languageform;
}
/**
* Submission method for the language selection form
*
* @param object $form
* @param array $data
*/
function language_select_form_submit($form, $data) {
global $SESSION;
// Pieforms will have already validated that $lang is an installed language or "default"
$SESSION->set('lang', $data['lang']);
redirect(get_relative_script_path());
}
/**
* Sanitises URIs provided before displaying them to the world, as well as checking they are of
* appropriate protocols and complete.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment