Hot answers tagged

3 votes

How can I ensure my_custom_module.install runs my_custom_module_update_8101()?

Update hooks are there to get the module into a known good state - the same state as when the module gets installed. It's for when you need to make changes to an already installed module, I'm not sure ...
user avatar
  • 164k
2 votes

How can I ensure my_custom_module.install runs my_custom_module_update_8101()?

In the code shown in the question, Database::getConnection()->exec($sql) will cause an error, since the object returned by Database::getConnection() (a Connection object) doesn't have any exec() ...
user avatar
  • 94.6k
1 vote
Accepted

How to get newly created user id in user_presave hook?

You can't get the user ID in a presave() hook for a new user because the ID isn't assigned until the user is saved. So how do I run code that uses the user ID when saving a user, regardless of whether ...
user avatar
1 vote
Accepted

How can I run a certain action when a taxonomy field value is removed or added?

Yes, hook_user_presave() is the way to go. Here's an example for a standard field. You'll need to tweak this a bit for a taxonomy entity reference. function MYMODULE_user_presave(UserBundle $user): ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible