1

I've got a custom module weekly_digest and I want to make it so each new user is added to a table with info on their subscription preferences.

I've been using the admin UI to add the users to test, unsure if that effects things but I don't see why it would.

As some context, in my .module I currently have weekly_digest_node_insert and that works just fine.

And here is the function which does not get executed and I can't get Xdebug to catch it either:

function weekly_digest_user_insert(UserInterface $entity) {

  $query = Drupal::database()->insert('weekly_digest_user_preferences');
  $query->fields([
    'uid',
  ])->useDefaults([
    'new_posts',
    'digests',
  ])->values([
    $entity->id(),
  ])->execute();

}

Most search results returned "Can't in theme" or "Drupal 7" so I was unable to figure this out.

2

It could be that you are using the incorrect argument. hook_ENTITY_TYPE_insert is a generic hook, it's not opinionated about what entity you are "inserting" (E.g. it could be a node, taxonomy, user...)

Try:

function weekly_digest_user_insert(\Drupal\Core\Entity\EntityInterface $entity) {
  // Do stuff.
}
| improve this answer | |
  • Are you saying I should change my parameter type to an EntityInterface? – Derek C. May 6 at 23:36
  • Yes, unless I am mistaken, I believe that is the correct approach. – 100pic May 7 at 0:52
  • I will try this out tomorrow and let you know! – Derek C. May 7 at 1:44
  • Yep that worked. I know I've seen others use UserInterface there but perhaps it was a drupal 7 site or something. – Derek C. May 7 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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