0

I need to add a hash key to users on register, generated from their email address and the current time, I added the field 'field_subscription_key' to user's fields and I hooked into

custom_newsletter_mail_user_insert(&$edit, $account, $category)

in module's .module file, I have no idea how can I get the email address and time the user was created from these above parameters.

Also, I don't know how to get the user entity, so I would insert the hash key.

3
  • Those arguments are not what Drupal 8 receives on hook_user_insert(). Either you are not actually using Drupal 8 or you are using wrong examples/documentation
    – Berdir
    Feb 20, 2018 at 18:46
  • I got this hook from the drupal 8 api docs at api.drupal.org/api/drupal/modules%21user%21user.api.php/… Feb 21, 2018 at 8:38
  • 1
    Make sure you read pages fully - you're using Drupal 8 but you're copying code from documentation that's clearly for Drupal 7
    – Clive
    Feb 21, 2018 at 9:42

1 Answer 1

2

The docs on the core entities are really good. Here are the docs on the User class.

You should be able to get the email with:

$email = $account->getEmail();

And the created time with:

$created = $account->getCreatedTime();
1
  • I got both the email and created time using your syntax, i got the hash key from them, then i used $account->set('field_subscription_key',$key); $account->save(); to save the subscription key but for some reason this is not working, the main problem is i cannot find a way to print the values and debug from this hook. Feb 21, 2018 at 8:37

Your Answer

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

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