n How to remove local tasks from login form in Drupal 8 & 9 | CodimTh

Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

How to remove local tasks from login form in Drupal 8 & 9

 

You can remove Create new account local task by allow only Administrators to create accounts, so just go to Configuration > Account settings > REGISTRATION AND CANCELLATION  and check Administrators only.

 

But the other two local tasks Log in and Reset your password there is no way to hide or remove them from the UI, the only way is to use hook_menu_local_tasks_alter :

/**
 * Implements hook_menu_local_tasks_alter().
 */
function YOURMODULE_menu_local_tasks_alter(&$data, $route_name) {
  if($route_name == 'user.login'  && isset($data['tabs'][0])) {
    // Remove all tabs from user login form.
    foreach ($data['tabs'][0] as $key => $tab){
      $data['tabs'][0][$key]['#access'] = FALSE;
    }
  }
}

Clear cache and you are done! 

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook