-5

This question already has an answer here:

I need to know please any suggestion about how to create a custom login form for another type of users in drupal 8 , I have now /user/login is for administrator, but I need to add /account/login it's different for the first one and it's for a normal user and this form should use the functionnalities of Drupal 8.

marked as duplicate by leymannx, No Sssweat, mradcliffe, Free Radical, sanzante Feb 3 at 10:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Isn't the user login form provided as a block? And you could create a page, put that block there and customize it? – leymannx Jan 28 at 17:56
0

Try with the following:

  1. Add your new route to [MODULE].routing.yml

[MODULE].login:
  path: '/account/login'
  defaults:
    _form: '\Drupal\[MODULE]\Form\CustomUserLoginForm'
    _title: 'Log in'
  requirements:
    _user_is_logged_in: 'FALSE'
  options:
    _maintenance_access: TRUE

  1. Create CustomUserLoginForm inside [MODULE]/src/Form/ folder like the following:

namespace Drupal\[MODULE]\Form;

use Drupal\user\Form\UserLoginForm;

class CustomUserLoginForm extends UserLoginForm{

}

  1. Flush the cache.
    it works but i don't know if it's the best approach.
  • Whats the difference though? It won't change any of the experience or routes after this user logs in. If its simply to change their login destination for example, there is a module that will do that. I don't think the question really has enough detail as to the purpose. – Kevin Jan 28 at 15:02
  • Thank you for your comment, but I already made that, my question is I want to know the core of the Login() function , like the process of the login in drupal 8 to make a login with the same approach of drupal 8 – Amine EL HADI Jan 28 at 15:51
  • If you want to know the login mechanism of the the process login take a look at UserLoginForm Class Here – berramou Jan 28 at 15:58
0

Try this solution :
1. add your roote to routing.yml

myModule.account:
path: /account/login
defaults:
_title: 'Connect'
_controller:

'\Drupal\myModule\Controller\AccountController::Login'
  1. Add your Controller file in
    myModule/src/Controller/AccountController.php

namespace Drupal\myModule\Controller;

use Drupal\Core\Controller\ControllerBase;
class AccountController extends ControllerBase
{
public function Login(){
}
  • Thank you for your comment asmaa, but I already made that, my question is I want to know the core of the Login() function , like the process of the login in drupal 8 , to make a login with the same approach of drupal 8 – Amine EL HADI Jan 28 at 15:48

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