0

I'm trying to display the user's language settings field on the registration page, but no success so far.

I've tried using a template (form--user-register-form.html.twig). This works for other fields, like mail, name, but I don't know how to access the language setting field.

I also tried form_alter (both in the theme and module MODULE_user_register_form_alter), and set $form['language']['#access'] = true; This hook doesn't seem to work at all, nothing happens when I try to use it (print out variables for example).

4
  • Did you check "Enable translation" on /admin/config/people/accounts? Then, did you go to /admin/config/people/accounts/form-display and make sure the "Language code" field was moved out of "Disabled"? Also, did you mean to name your twig file form--user-register-from.html.twig or form--user-register-form.html.twig
    – andileco
    Feb 26, 2018 at 18:54
  • I checked "Enable translation" (what does that do btw?), but it didn't make any difference. The language code is also enabled. I also don't know what's the difference between the language code field and the language settings field though. The 'from' was just a typo. Interestingly, I could set the $form['language']['#access'] = true; in the twig template, and it made the language settings box visible, but the select is missing from it. I wonder if it's maybe a permission issue (something that the anonymous user doesn't have, but I couldn't find anything).
    – keszthelyi
    Feb 27, 2018 at 9:22
  • The only way I could display it, if I give the Anonymous user the permission to 'Administer users'. That is not really a solution, but that seems to be the permission that makes it available.
    – keszthelyi
    Feb 27, 2018 at 9:48
  • If the D7 solution is any guide, I think you need a form alter hook to change the #access value for the element. Feb 27, 2018 at 11:32

1 Answer 1

0

This is an old question but there's a current issue opened on Drupal core for this here https://www.drupal.org/project/drupal/issues/3163758

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.