Only beginner can ask this type of question. as i am learning drupal recently. what is the first function that executes in .module file..how can i understand which function or hook executed.I just want to analyse the execution..please help me out.
1 Answer
what is the first function that executes in .module file? - none in the C sense. If you came from C, C++ or C# environment, think of modules like you think of dll / so files. If you came from Java, think of them like you think of libraries. Piece of code that is hooked by the program if needed, and provides functions that can be called as needed.
So which function is called first? One that implements hook that, by accident, happens to be needed first.
Drupal modules provide functions that react to certain events. These functions are called hooks. Introduction to hooks is in the Develop for Drupal documentation.
Note: As Ayesh K helpfully pointed, PHP code placed in module file will usually be executed at every call. But Drupal expects there is no code outside functions in .module files. Placing direct PHP code may cause unexpected behaviour, so please don't do it.
-
+1 for the comparison between with C/C++
main()
. However, code in .module files are loaded for every call by default. I think it'd be more accurate if we sayhooked by the program if needed
.– AKSSep 23, 2014 at 14:57 -
-
@shridhar If you feel it's helpful. approve this answer so that it would be helpful for future readers :) Sep 24, 2014 at 9:31
-
@KrishnaMohan actually accepting answers is not mandatory, and future readers will see that it got some upvotes, so at least 4 people thinks it is a good answer. Of course it would be nice if OP would accept this, but no real harm done if he will not.– MołotSep 24, 2014 at 9:45
-
@Mołot Yes I agree that. I just wanted to notify him(OP). If he approves, at least it would disappear from unanswered list, infact I forgot to include this point. Sep 24, 2014 at 10:02
main()
function as such. The paradigm is AOP (something you may or may not be familiar with if you're coming from a C background). Reading the answers to this question should give you a good grounding in how things work, and maybe help you to narrow down a more specific question to ask. The docs @Smalution linked to will help too