1

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.

4
  • 2
    you need to learn basic tutorials for building a drupal module. Refer drupal.org/developing/modules
    – DRUPWAY
    Sep 20, 2014 at 12:15
  • 4
    Welcome to Drupal Answers :) Drupal modules aren't functionality similar to a C program, there's no equivalent of a 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
    – Clive
    Sep 20, 2014 at 12:15
  • i have done some editing to my question
    – Shridhar
    Sep 22, 2014 at 6:05
  • 1
    @shridhar Could you explain how your edit changes the question? If you want to analyse the execution the obvious (and simplest) way would be to step through with a debugger. Every page request is different in Drupal, and even trying to explain all the nuances of a single page execution is much too broad for what we can cover here. Could you narrow down your question to something specific? For example, "At what point the bootstrap is the session instantiated?". Without that information this will inevitably be closed as too broad, we can't talk you through every line of a Drupal page build
    – Clive
    Sep 23, 2014 at 15:29

1 Answer 1

5

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.

7
  • +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 say hooked by the program if needed.
    – AKS
    Sep 23, 2014 at 14:57
  • @AyeshK Better now?
    – Mołot
    Sep 24, 2014 at 6:43
  • @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łot
    Sep 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

Your Answer

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

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