Introduction to Module Development

download Introduction to Module Development

of 15

Transcript of Introduction to Module Development

  • 8/12/2019 Introduction to Module Development

    1/15

    Drupal Module

    Development

  • 8/12/2019 Introduction to Module Development

    2/15

    Open Source CMS

    Content Management Systems managewebsite (or intranet) content

    Open Source Content Management

    Systems have become one of the realopen source success stories

    The three most popular open source

    CMS in the nonprofit sector are: Joomla

    Drupal

    Plone

  • 8/12/2019 Introduction to Module Development

    3/15

    What does a module do?

    Core modules provides functionality Contributed modules extends functionality

    Custom modules defines new functionality

    A Custom module is one which is local to yourDrupal Project. It's not yet contributed to thecontrib repository

  • 8/12/2019 Introduction to Module Development

    4/15

    Custom Module(When to write)

    You need to answer few questions before writing aCustom Module

    1. What do you want to achieve by this custom module?

    2. Did you search the Contrib Repository to see if a

    module is already available for that feature?3. Have you enabled all possible Configurations of the

    Core & Contrib module to check if they offer you thefeature you require?

    If your answer is, Yes, I have done enough research and

    am sure I have to write the code now, then go ahead ....

  • 8/12/2019 Introduction to Module Development

    5/15

    Custom Module(Why to write)

    I need a new feature which is not yetavailable in Drupal, and probably can becontributed as a Contrib Module.

    I don't want to keep adding additionalmodules to my site for small tweaks, whichI can manage in only one custom modulefor my website. Don't be too muchdependent on Contribs.

  • 8/12/2019 Introduction to Module Development

    6/15

    Examples of modules

    Core required modules: System, Filter, Node, Block, User

    Core optional modules:

    Taxonomy, Menu, Comment, Search 3rd party modules:

    Views, Panels, CCK, Devel

  • 8/12/2019 Introduction to Module Development

    7/15

    Hooks

    Can be thought of as internal Drupalevents

    Allow modules to interact with the Drupal

    core Events include:

    Creation, deletion of nodes and users

    Logging in, logging out

    Hooks can also create and alter menusand forms

  • 8/12/2019 Introduction to Module Development

    8/15

    Hook examples

    hook_user login, logout, insert, view, update

    hook_block

    view, save, configure, list hook_form_alter

    hook_insert

    hook_comment insert, update, view, publish, unpublish

  • 8/12/2019 Introduction to Module Development

    9/15

    Useful modules/tools

    Devel (drupal.org/project/devel)Admin Menu

    (drupal.org/project/admin_menu)

    Drush (drupal.org/project/drush)Any others?

  • 8/12/2019 Introduction to Module Development

    10/15

    Simple Module Structure

  • 8/12/2019 Introduction to Module Development

    11/15

    Our first module

    Hello World module Two files required for a module:

    helloworld.info

    helloworld.module (Optionally) helloworld.install

    helloworld

    helloworld.infohelloworld.module

  • 8/12/2019 Introduction to Module Development

    12/15

    Our first module

    Where should I put my module? /path_to_drupal/modules

    /path_to_drupal/sites/all/modules/

  • 8/12/2019 Introduction to Module Development

    13/15

    helloworld.info

    ; $Id$name = Hello World

    description = Creates a Hello World Content

    package = Module Dev Training

    core = 6.x

  • 8/12/2019 Introduction to Module Development

    14/15

    helloworld.module

  • 8/12/2019 Introduction to Module Development

    15/15

    Drupal Module

    Development

    ICT CenterWe are making IT happen

    IC

    T

    Integrity

    Commitment

    Teamwork