@@ -509,12 +509,22 @@ public function pageRegister(Request $request, Response $response, $args)
509509 // Get locale information
510510 $ currentLocales = $ localePathBuilder ->getLocales ();
511511
512+ // Hide the locale field if there is only 1 locale available
513+ $ fields = [
514+ 'hidden ' => [],
515+ 'disabled ' => []
516+ ];
517+ if (count ($ config ->getDefined ('site.locales.available ' )) <= 1 ) {
518+ $ fields ['hidden ' ][] = 'locale ' ;
519+ }
520+
512521 return $ this ->ci ->view ->render ($ response , 'pages/register.html.twig ' , [
513522 'page ' => [
514523 'validators ' => [
515524 'register ' => $ validatorRegister ->rules ('json ' , false )
516525 ]
517526 ],
527+ 'fields ' => $ fields ,
518528 'locales ' => [
519529 'available ' => $ config ['site.locales.available ' ],
520530 'current ' => end ($ currentLocales )
@@ -658,8 +668,18 @@ public function pageSettings(Request $request, Response $response, $args)
658668 // Get a list of all locales
659669 $ locales = $ config ->getDefined ('site.locales.available ' );
660670
671+ // Hide the locale field if there is only 1 locale available
672+ $ fields = [
673+ 'hidden ' => [],
674+ 'disabled ' => []
675+ ];
676+ if (count ($ config ->getDefined ('site.locales.available ' )) <= 1 ) {
677+ $ fields ['hidden ' ][] = 'locale ' ;
678+ }
679+
661680 return $ this ->ci ->view ->render ($ response , 'pages/account-settings.html.twig ' , [
662681 'locales ' => $ locales ,
682+ 'fields ' => $ fields ,
663683 'page ' => [
664684 'validators ' => [
665685 'account_settings ' => $ validatorAccountSettings ->rules ('json ' , false ),
@@ -766,6 +786,11 @@ public function profile(Request $request, Response $response, $args)
766786
767787 $ error = false ;
768788
789+ // Ensure that in the case of using a single locale, that the locale is set
790+ if (count ($ config ->getDefined ('site.locales.available ' )) <= 1 ) {
791+ $ data ['locale ' ] = $ currentUser ->locale ;
792+ }
793+
769794 // Validate, and halt on validation errors.
770795 $ validator = new ServerSideValidator ($ schema , $ this ->ci ->translator );
771796 if (!$ validator ->validate ($ data )) {
@@ -877,6 +902,11 @@ public function register(Request $request, Response $response, $args)
877902
878903 $ error = false ;
879904
905+ // Ensure that in the case of using a single locale, that the locale is set
906+ if (count ($ config ->getDefined ('site.locales.available ' )) <= 1 ) {
907+ $ data ['locale ' ] = $ config ['site.registration.user_defaults.locale ' ];
908+ }
909+
880910 // Validate request data
881911 $ validator = new ServerSideValidator ($ schema , $ this ->ci ->translator );
882912 if (!$ validator ->validate ($ data )) {
@@ -913,12 +943,9 @@ public function register(Request $request, Response $response, $args)
913943 // Now that we check the form, we can register the actual user
914944 $ registration = new Registration ($ this ->ci , $ data );
915945
916- try {
917- $ user = $ registration ->register ();
918- } catch (\Exception $ e ) {
919- $ ms ->addMessageTranslated ('danger ' , $ e ->getMessage (), $ data );
920- $ error = true ;
921- }
946+ // Try registration. An HttpException will be thrown if it fails
947+ // No need to catch, as this kind of exception will automatically returns the addMessageTranslated
948+ $ user = $ registration ->register ();
922949
923950 // Success message
924951 if ($ config ['site.registration.require_email_verification ' ]) {
@@ -1163,6 +1190,11 @@ public function settings(Request $request, Response $response, $args)
11631190
11641191 $ error = false ;
11651192
1193+ // Ensure that in the case of using a single locale, that the locale is set
1194+ if (count ($ config ->getDefined ('site.locales.available ' )) <= 1 ) {
1195+ $ data ['locale ' ] = $ currentUser ->locale ;
1196+ }
1197+
11661198 // Validate, and halt on validation errors.
11671199 $ validator = new ServerSideValidator ($ schema , $ this ->ci ->translator );
11681200 if (!$ validator ->validate ($ data )) {
0 commit comments