How can I get form values like first name, last name, email and password in hook_user_insert() in Drupal 8?

  • You can't, for this you would have to add a submit function in a form alter hook. But as the default submit has already run you'll find probably the values now inside of the entity.
    – 4uk4
    Jun 19, 2017 at 7:30
  • 1
    Can you edit the question to give more information on what you wish to achieve. Then maybe you will get a more helpful answer.
    – Alma
    Jun 19, 2017 at 8:04

1 Answer 1


The $account argument have the data that you like, but the password is protected.

It's not the best practice, but you can use reflection to get it:

/** @var \Drupal\Core\Field\FieldItemList $passObject */
$passObject = $account->get('pass');
/** @var \Drupal\Core\Field\Plugin\Field\FieldType\PasswordItem $passItem */
$passItem = $passObject->get(0);
$reflection = new \ReflectionClass($passItem);
$reflectionProperty = $reflection->getProperty('values');
// This do the magic.
$pass = $reflectionProperty->getValue($passItem)['value'];

See more about hook_user_insert here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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