0

I want to change the labels "Username" and "Password" and delete "Create new account" link of the standard login form of Drupal 8. Is it possible to do this with twig? this login form

3
  • 5
    Does this answer your question? How to customize the user login form? – leymannx May 23 '20 at 11:27
  • 1
    Yes, thanks. I changed the labels. But I also need to remove "Create new account" link or at least both links. I don't want to hide them with CSS – Universaldenker May 23 '20 at 14:45
  • @Universaldenker you might want to consider editing the question title and body to reflect that you want to change the default route to the user_login_form as well as the presentation. – hotwebmatter May 26 '20 at 3:17
3

I found the solution how to add user and password placeholders an modify user and password labels:

function THEMENAME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form_id == 'user_login_form' ) {
    // Add placeholders.
    $form['name']['#attributes']['placeholder'] = t('User Placeholder Text Here');
    $form['pass']['#attributes']['placeholder'] = t('Password Placeholder Text Here');

    // Labels
    $form['name']['#title'] = t('User Label Here');
    $form['pass']['#title'] = t('Password Label Here');

    //Submit Value
    $form['actions']['submit']['#value'] = t('Submit Button Text Here');
  }
}

To remove "Create new account" and "Reset your password" links, just override block--user-login-block.html.twig file. Change

{{ content }} 

to

{{ content|without('user_links') }}
2

To remove the "Create new account" function permanently, using Twig or render hooks is not enough: Drupal-savvy visitors may type the correct URL directly in their browsers. There are bots that attempt to create accounts automatically.

To remove the "Create new account" link AND disable account creation, go to Administration » Configuration » People and find the option "Who can register accounts?". Set it to "Administrators only".

1
  • 1
    I want to place a custom register link somewhere else and just remove the standard login form link. I don't want to hide it with css – Universaldenker May 23 '20 at 14:15
1

@leymannx and @Gogowitsch have answered the original question quite admirably. However, OP has added another question in the comments:

I want to place a custom register link somewhere else and just remove the standard login form link. I don't want to hide it with css

Since OP wants to change not only the login form, but also the URL, the Login Switch contributed module might be just what they are looking for.

Login Switch

This module will allow you to change the default login URL and disable the normal /user/login route built into core. Hackers today know all the usual entry points for the common CMS systems so the first step to securing your site it is to change the entry they know about.

This could be used in combination with the hook_form_alter() of the $form_id == 'user_login_form' recommended in the comments above.

0

Yes, you change the labels "Username" and "Password" by using stringoverrides module https://www.drupal.org/project/stringoverrides or you will able to hide or delete "Create new account" using twig and css.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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