Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zviryatko
Last active March 17, 2016 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zviryatko/ea4f791614b9093629cf to your computer and use it in GitHub Desktop.
Save zviryatko/ea4f791614b9093629cf to your computer and use it in GitHub Desktop.
Disable user nick name in Drupal 8
<?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