I want to remove the following default links on the login block.
- Create new account
- Reset your password
I used hook_form_alter()
but there is nothing in there that creates these links.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityMethod #1
Implement hook_preprocess_block() in your module/theme.
/**
* Implements hook_preprocess_HOOK().
*/
function HOOK_preprocess_block__user_login_block(&$variables) {
$variables['content']['user_links']['#access'] = FALSE;
}
Method #2
Override block--user-login-block.html.twig template and replace {{ content }}
with the following {{ content|without('user_links') }}
.
Note that hiding those links would not protect respective pages (user/register and user/password) from direct access.
It's better to set proper permissions, because removing the links won't prevent users from typing user/register
and user/password
in the browser's address bar and reaching them directly.
However, if you really want to remove those links from the login block using the hook, then the following code should work:
function hook_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_login_block') {
unset($form['links']);
}
}