diff --git a/app/sprinkles/account/src/Controller/AccountController.php b/app/sprinkles/account/src/Controller/AccountController.php index 46d890896..fab4c09de 100644 --- a/app/sprinkles/account/src/Controller/AccountController.php +++ b/app/sprinkles/account/src/Controller/AccountController.php @@ -509,12 +509,22 @@ public function pageRegister(Request $request, Response $response, $args) // Get locale information $currentLocales = $localePathBuilder->getLocales(); + // Hide the locale field if there is only 1 locale available + $fields = [ + 'hidden' => [], + 'disabled' => [] + ]; + if (count($config->getDefined('site.locales.available')) <= 1) { + $fields['hidden'][] = 'locale'; + } + return $this->ci->view->render($response, 'pages/register.html.twig', [ 'page' => [ 'validators' => [ 'register' => $validatorRegister->rules('json', false) ] ], + 'fields' => $fields, 'locales' => [ 'available' => $config['site.locales.available'], 'current' => end($currentLocales) @@ -658,8 +668,18 @@ public function pageSettings(Request $request, Response $response, $args) // Get a list of all locales $locales = $config->getDefined('site.locales.available'); + // Hide the locale field if there is only 1 locale available + $fields = [ + 'hidden' => [], + 'disabled' => [] + ]; + if (count($config->getDefined('site.locales.available')) <= 1) { + $fields['hidden'][] = 'locale'; + } + return $this->ci->view->render($response, 'pages/account-settings.html.twig', [ 'locales' => $locales, + 'fields' => $fields, 'page' => [ 'validators' => [ 'account_settings' => $validatorAccountSettings->rules('json', false), @@ -766,6 +786,11 @@ public function profile(Request $request, Response $response, $args) $error = false; + // Ensure that in the case of using a single locale, that the locale is set + if (count($config->getDefined('site.locales.available')) <= 1) { + $data['locale'] = $currentUser->locale; + } + // Validate, and halt on validation errors. $validator = new ServerSideValidator($schema, $this->ci->translator); if (!$validator->validate($data)) { @@ -877,6 +902,11 @@ public function register(Request $request, Response $response, $args) $error = false; + // Ensure that in the case of using a single locale, that the locale is set + if (count($config->getDefined('site.locales.available')) <= 1) { + $data['locale'] = $config['site.registration.user_defaults.locale']; + } + // Validate request data $validator = new ServerSideValidator($schema, $this->ci->translator); if (!$validator->validate($data)) { @@ -1163,6 +1193,11 @@ public function settings(Request $request, Response $response, $args) $error = false; + // Ensure that in the case of using a single locale, that the locale is set + if (count($config->getDefined('site.locales.available')) <= 1) { + $data['locale'] = $currentUser->locale; + } + // Validate, and halt on validation errors. $validator = new ServerSideValidator($schema, $this->ci->translator); if (!$validator->validate($data)) { diff --git a/app/sprinkles/account/templates/forms/settings-profile.html.twig b/app/sprinkles/account/templates/forms/settings-profile.html.twig index 0b0a788ab..109bc5576 100644 --- a/app/sprinkles/account/templates/forms/settings-profile.html.twig +++ b/app/sprinkles/account/templates/forms/settings-profile.html.twig @@ -20,6 +20,7 @@ + {% if 'locale' not in fields.hidden %}

{{translate("LOCALE.ACCOUNT")}}.

+ {% endif %} {% endblock %} + {% if 'locale' not in fields.hidden %}

{{translate("LOCALE.ACCOUNT")}}.

+ {% endif %} {% if site.registration.captcha %}
diff --git a/app/sprinkles/admin/src/Controller/UserController.php b/app/sprinkles/admin/src/Controller/UserController.php index d6293ec49..0ea0e2c1d 100644 --- a/app/sprinkles/admin/src/Controller/UserController.php +++ b/app/sprinkles/admin/src/Controller/UserController.php @@ -60,6 +60,9 @@ public function create(Request $request, Response $response, $args) /** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */ $currentUser = $this->ci->currentUser; + /** @var \UserFrosting\Support\Repository\Repository $config */ + $config = $this->ci->config; + // Access-controlled page if (!$authorizer->checkAccess($currentUser, 'create_user')) { throw new ForbiddenException(); @@ -77,6 +80,11 @@ public function create(Request $request, Response $response, $args) $error = false; + // Ensure that in the case of using a single locale, that the locale is set bu inheriting from current user + if (count($config->getDefined('site.locales.available')) <= 1) { + $data['locale'] = $currentUser->locale; + } + // Validate request data $validator = new ServerSideValidator($schema, $this->ci->translator); if (!$validator->validate($data)) { @@ -573,6 +581,11 @@ public function getModalCreate(Request $request, Response $response, $args) $fields['disabled'][] = 'group'; } + // Hide the locale field if there is only 1 locale available + if (count($config->getDefined('site.locales.available')) <= 1) { + $fields['hidden'][] = 'locale'; + } + // Create a dummy user to prepopulate fields $data = [ 'group_id' => $currentUser->group_id, @@ -673,6 +686,11 @@ public function getModalEdit(Request $request, Response $response, $args) $fields['disabled'][] = 'group'; } + // Hide the locale field if there is only 1 locale available + if (count($config->getDefined('site.locales.available')) <= 1) { + $fields['hidden'][] = 'locale'; + } + // Load validation rules $schema = new RequestSchema('schema://requests/user/edit-info.yaml'); $validator = new JqueryValidationAdapter($schema, $this->ci->translator); @@ -950,6 +968,11 @@ public function pageInfo(Request $request, Response $response, $args) } } + // Hide the locale field if there is only 1 locale available + if (count($config->getDefined('site.locales.available')) <= 1) { + $fields['hidden'][] = 'locale'; + } + // Determine buttons to display $editButtons = [ 'hidden' => []