13
Modules in Drupal 7 Basics - introduction to Modules in drupal 7

Introduction And Basics of Modules in Drupal 7

Embed Size (px)

Citation preview

Page 1: Introduction And Basics of Modules in Drupal 7

Modules in Drupal 7Basics - introduction to Modules in drupal 7

Page 2: Introduction And Basics of Modules in Drupal 7

Modules in drupal are used to extend and customize the drupal

features and functionality. Its like a library / plugin in drupal 7.

There are thousands of module available on the drupal.org

community. One of most important and major section in drupal

website development. Modules can be easily map with the system

intro

Page 3: Introduction And Basics of Modules in Drupal 7

● Core - with comes default in the drupal core. you will find it

in root_dictory/modules.

● Contributed - Developed by the contributor of the drupal

community. developer need to install on the system if need.

you can find it in root_diretory/sites/all/modules.

● Custom - written by developer. to achieve this should

technical skills includes php,drupal coding standard.you can

find it in root_diretory/sites/all/modules

Types of module

Page 4: Introduction And Basics of Modules in Drupal 7

.info - The information about the module file is called

“.info”.There can be additional values, but these are the

essentials. The syntax is a simple label equals value

pairing.

.inc - The functional code of section like views, admin , hooks

methods can be derived at inc files [optional].

dependencies[ ] - If your module needs some other module to

work. the module name you can mention in dependencies section.

Modules file architecture

Page 5: Introduction And Basics of Modules in Drupal 7

name = Mymodule (Human-readable name of our module )

description = Shows functionalities of my website. (Describes

what our module does in a sentence or two)

core = 7.x

; Require the core Help module and the contrib Views module to

be enabled.

dependencies[] = help

dependencies[] = views

Sample code “mymodule.info” file:

Page 6: Introduction And Basics of Modules in Drupal 7

The functional code of the module file is called .module”. The

“.module” file must have the same machine name as the .info

file,which for both should be the same name as the folder they are

in.

Mostly contains the hooks and major part of the modules function

declaration.

“.module” File

Page 7: Introduction And Basics of Modules in Drupal 7

<?php

/**

* @file

* Helps site builders and module developers investigate a site.

*/

/**

* Implements hook_form_alter() to show each form's identifier.

*/

function mymodule_form_alter(&$form, &$form_state, $form_id) {

$form['mymodule_display_form_id'] = array('#type' => 'item','#title' => t('Form ID'),

'#markup' => $form_id,'#weight' => -100,);

}

Page 8: Introduction And Basics of Modules in Drupal 7

The configure directive, optional but highly recommended, lets

you provide the path to your module’s configuration page. Drupal

uses this path to provide a link on the Modules administration

page when the module is enabled. you have to mention in .info

file.

The following is an example of a configure directive from the

core search module:

configure = admin/config/search/settings

Configure option

Page 9: Introduction And Basics of Modules in Drupal 7

place your module on the root_directory/sites/all/module/module.

Goto Admin Menu => modules. you can see all core and

contributed modules.click on enabled option and save. if want

disable uncheck the option and save for the same. Also any

configuration and permission needed for the module you can see

configure & permission link corresponding to the module name.

To uninstall - Admin Menu => modules you will find “uninstall”

tab on top right. check the list of module proceed uninstall.

uninstall option will completely remove your physical datatables

related to the modules.

Module enable/disable/uninstall

Page 10: Introduction And Basics of Modules in Drupal 7
Page 11: Introduction And Basics of Modules in Drupal 7

The hooks allows in module do something before the it is get

executed. Its almost like event listener whenever an action taken

place in drupal like saving,editing,deleting comments, node, users

the system invites all any module involved.Every hook is an

opportunity for your module to take action in response to

something Drupal is doing. Apptx around 250 hooks are there in

drupal system. hook is the placeholder your module name will be

replaced there.

Hooks

Page 12: Introduction And Basics of Modules in Drupal 7

function mymodule_help($path, $arg) {

if ($path == 'admin/structure') {

return t('This site has stuff!');

}

}

Styling Your Module : Adding a CSS File

you can all the css files needed for your module in .info file.

stylesheets[all][] = mymodule.css

Sample Code

Page 13: Introduction And Basics of Modules in Drupal 7

Thank U

Dhinakaran M