Last active
March 17, 2016 08:03
-
-
Save zviryatko/ea4f791614b9093629cf to your computer and use it in GitHub Desktop.
Disable user nick name in Drupal 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use \Drupal\user\UserInterface; | |
use \Drupal\Component\Utility\Random; | |
/** | |
* Implements hook_ENTITY_TYPE_create(). | |
*/ | |
function custom_user_user_presave(UserInterface $entity) { | |
$entity->setUsername($entity->getEmail()); | |
} | |
/** | |
* Implements hook_form_FORM_ID_alter(). | |
*/ | |
function custom_user_form_user_form_alter(&$form) { | |
$form['account']['mail']['#required'] = TRUE; | |
$form['account']['name']['#access'] = FALSE; | |
$random = new Random(); | |
$form['account']['name']['#default_value'] = $random->name(); | |
} | |
/** | |
* Implements hook_form_FORM_ID_alter(). | |
*/ | |
function custom_user_form_user_register_form_alter(&$form) { | |
custom_user_form_user_form_alter($form); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment