Allow users to change their Language via the Edit Profile page.
This commit is contained in:
parent
73ea94c7a2
commit
b99b09d13c
5 changed files with 85 additions and 13 deletions
|
|
@ -66,22 +66,34 @@ class UserController extends Controller
|
|||
{
|
||||
$user = $_SESSION['phpci_user'];
|
||||
|
||||
$this->layout->title = $user->getName();
|
||||
$this->layout->subtitle = Lang::get('edit_profile');
|
||||
|
||||
if ($this->request->getMethod() == 'POST') {
|
||||
$name = $this->getParam('name', null);
|
||||
$email = $this->getParam('email', null);
|
||||
$password = $this->getParam('password', null);
|
||||
|
||||
$currentLang = Lang::getLanguage();
|
||||
$chosenLang = $this->getParam('language', $currentLang);
|
||||
|
||||
if ($chosenLang !== $currentLang) {
|
||||
setcookie('phpcilang', $chosenLang, time() + (10 * 365 * 24 * 60 * 60), '/');
|
||||
Lang::setLanguage($chosenLang);
|
||||
}
|
||||
|
||||
$_SESSION['phpci_user'] = $this->userService->updateUser($user, $name, $email, $password);
|
||||
$user = $_SESSION['phpci_user'];
|
||||
|
||||
$this->view->updated = 1;
|
||||
}
|
||||
|
||||
$this->layout->title = $user->getName();
|
||||
$this->layout->subtitle = Lang::get('edit_profile');
|
||||
|
||||
$values = $user->getDataArray();
|
||||
|
||||
if (array_key_exists('phpcilang', $_COOKIE)) {
|
||||
$values['language'] = $_COOKIE['phpcilang'];
|
||||
}
|
||||
|
||||
$form = new Form();
|
||||
$form->setAction(PHPCI_URL.'user/profile');
|
||||
$form->setMethod('POST');
|
||||
|
|
@ -107,6 +119,14 @@ class UserController extends Controller
|
|||
$password->setRequired(false);
|
||||
$form->addField($password);
|
||||
|
||||
$lang = new Form\Element\Select('language');
|
||||
$lang->setClass('form-control');
|
||||
$lang->setContainerClass('form-group');
|
||||
$lang->setLabel(Lang::get('language'));
|
||||
$lang->setRequired(true);
|
||||
$lang->setOptions(Lang::getLanguageOptions());
|
||||
$form->addField($lang);
|
||||
|
||||
$submit = new Form\Element\Submit();
|
||||
$submit->setClass('btn btn-success');
|
||||
$submit->setValue(Lang::get('save'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue