This question already has an answer here:

I'm learning to create custom modules in Drupal 8, and in this context I bought a book. Somewhere in the book they told me to do something using hooks, but I have never used hooks before, and I even don't know what they are. So I looked it up on Google and find out that they are being used to extend and modify Drupal's functionality, but I still have a question: How do they function and how do I use them?

I say thanks to all answers :)

marked as duplicate by Kevin, Neograph734, Beebee, Pierre.Vriens, Clive Sep 21 '17 at 14:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Hooks are functions that we use in our custom module's *.module file. By using those functions we can hook our code snippet to drupal core functions. For example -

hook_block_view_alter() will alter the block.

You can know more about the particular hook by looking them up in api.drupal.org

By the way, hooks are going to deprecate in upcoming drupal versions. Therefore, from drupal 8 onwards we are using OOP approach to develop custom module.

Hope my explaination helps.

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