Drupal Modules

60 %
40 %
Information about Drupal Modules

Published on October 25, 2007

Author: teamphp

Source: slideshare.net

Description

How to build Modules in Drupal

Well Come to all of you in Drupal (CMS) Session . Developed By. Kunal Guide by: Amit What is Drupal? Drupal is used to build web sites. It’s a highly modular, open source web content management framework Last Updated: October 17 2007

Generally there are four types of files in drupal we used. These files extension are 1) .CSS 2) .Info 3) .Install 4) .Module Shortly introduction about above files. 1) .Css :-> Use of css files for change the layout of that perticular module. 2) .Info :-> This file is like the .ini file in windows. the concept of a .info file has been introduced to give Drupal a little more information about your module. 3) .Module :-> Total Functionality about your module. Last Updated: October 17 2007

MODULES: Drupal is a truly modular framework. Functionality is included in modules, which can be enabled or disabled (some required modules cannot be disabled). Features are added to a Drupal web site by enabling existing modules, installing modules written by members of the Drupal community,or writing new modules. Drupal makes use of the inversion of control design pattern, in which modular functionality is called by the framework at the appropriate time. These opportunities for modules to do their thing are called hooks. Hooks: Hooks can be thought of as internal Drupal events. They are also called callbacks, though because they are constructed by function naming conventions and not by registering with a listener, they are not truly being called back. Hooks allow modules to “hook into” what is happening in the rest of Drupal.Suppose a user logs into your Drupal web site. At the time the user logs in, Drupal fires the user hook. That means that any function named according to the convention module name plus hook name will be called. Blocks: A block is information that can be enabled or disabled in a specific location on your web site’s template. For example, a block might display the number of current active users on your site.You might have a block containing the most active users, or a list of upcoming events. Blocks are typically placed in a template’s sidebar, header, or footer. Blocks can be set to display on nodes of a certain type, only on the front page, or according to other criteria. Last Updated: October 17 2007

.Info :-> This file is like the .ini file in windows. the concept of a .info file has been introduced to give Drupal a little more information about your module.This file is used primarily by the modules administration system for display purposes as well as providing criteria to control activation and deactivation. This file is required for Drupal 5 to recognize the presence of a module.The .info file should have the same name as the .module file and reside in the same directory. For example, if your module is named example.module then your .info file should be named example.info.info files may contain comments. The comment character is the semi-colon and denotes a comment until the end of the line. A comment may begin at any point on the line, thus it is especially important you quote any string that contains a comment. It is typical to place the CVS Id at the top of a .info file using a comment: The .info file can contain the following fields: A) name (Required): The displayed name of your module. It should follow the Drupal 5 capitalization standard: only the first letter of the first word is capitalized Ex. name = &quot;Forum&quot; B) description (Required) : A short, preferably one line description that will tell the administrator what this module does on the module administration page. Remember, overly long descriptions can make this page difficult to work with, so please try to be concise. This field is limited to 255 characters.Ex. description = &quot;Enables threaded discussions about general topics.“ If your .info file's description (or other field) contains characters other than alphanumeric values then you must quote the string. If you need to use &quot; in the string then you need to use the &quot; value to display the &quot; character.For example, this will display correctly: description = &quot;This is my &quot;crazy@email.com&quot; email address“ This is wrong and cause Drupal to display an error when going to the modules menu:description = This is my &quot;crazy@email.com&quot; address <- DO NOT DO THIS Last Updated: October 17 2007 Next Page Next Page

C) dependencies (Optional): A space separated list of other modules that your module requires. If these modules are not present, your module can not be enabled. If these modules are present but not enabled, the administrator will be prompted with a list of additional modules to enable and may choose to enable the required modules as well, or cancel at that point. Ex. dependencies = taxonomy comment D) package (Optional): If your module comes with other modules or is meant to be used exclusively with other modules, enter the name of the package here. If left blank, the module will be listed as 'Other'. Ex. package = Views Suggested examples of appropriate items for the package field: 1) Chat 2) Location 3) View 4) Event 5) Video E) version (Optional): Display the version of your modules. Ex. version = 1.1 F) project (packaging use only): Module maintainers should not use this at all. The packaging script on drupal.org will automatically place a string here to identify what project the module came from. This is primarily for the Update status module, so that Drupal installations can monitor versions of installed packages and notify administrators when new versions are available. Last Updated: October 17 2007

3) .Install :-> .install files to do module setup work. A .install file is run the first time a module is enabled, and is used to do setup required by the module. The most common task is creating database tables and fields . .install files are also used to perform updates when a new version of a module needs it. There are three functions in .install files. 1) _install() 2) _Update_x() 3) _Uninstall() Use of _install() function is to install the or create the tables in your database. There are two types of labraries/Packages are used by Drupal. These are MySqli & PgSql Note about already installed modules If the module you are writing the .install file for is already installed then the install/update(s) will not trigger even if you disable/enable it. You need to disable the module and remove its record manually form the system table or include a hook_uninstall function. Last Updated: October 17 2007 Next Page Next Page

Syntax For _Install(): function xyz_install() { switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': db_query(&quot;CREATE TABLE {xyz_data} ( vid int unsigned NOT NULL default '0', field_name varchar(32) NOT NULL default '')); break; case 'pgsql': db_query(&quot;CREATE TABLE {xyz_data} ( vid serial CHECK (vid >= 0), field_name varchar(32) NOT NULL default '')); db_query(&quot;CREATE INDEX {xyz_data}_field_name_idx ON {xyz_data} (field_name)&quot;); break; } } Last Updated: October 17 2007 Next Page Next Page

use of _update_x(): .install files can also include update instructions, which are used through update.php like regular Drupal updates. Each update is placed in a modulename_update_x() function (where x is an incrementing integer). Updates should always increment by 1. Syntax For _update_x(): function example_update_1() { $items = array(); $items[] = update_sql(&quot;ALTER TABLE {example} ADD new_column text&quot;); $items[] = update_sql(&quot;ALTER TABLE {example} DROP old_column&quot;); return $items; } Last Updated: October 17 2007 Next Page Next Page

The _uninstall function is also available in a .install file and gets fired when a module is uninstalled. This function generally includes dropping tables and deleting variables specific to that module. Syntax _uninstall(): function search_uninstall() { db_query('DROP TABLE {xyz_data}'); db_query('DROP TABLE {xyz_index}'); db_query('DROP TABLE {search_total}'); variable_del('minimum_word_size'); variable_del('overlap_cjk'); } Last Updated: October 17 2007 Next Page Next Page

In Your .Module files you use the hook’s as a function name. suppose _help is the name of your hook then the name of function should be xyz_help() And the xyz is name of your module. There are certain rules while writing the modules. Last Updated: October 17 2007

It is an Practical implementations so I will show you one module practically. (.Module) File Last Updated: October 17 2007

It is an Practical implementations so I will show you one module practically.

Pune It Labs. Last Updated: October 17 2007 Thank You Any Questions?

Pune It Labs.

Add a comment

Related pages

Module project | Drupal.org - Drupal - Open Source CMS ...

Extend and customize Drupal functionality with contributed modules. If a module doesn't quite do what you want it to do, if you find a bug or have a ...
Read more

Drupal Modules - Search, Rate, and Review Drupal Modules

Ratings and reviews for thousands of Drupal Modules. Search, download, and find the best modules. RSS feeds for top rated, most popular, new modules, and more.
Read more

Drupal - Open Source CMS | Drupal.org

Drupal Jobs. Find your next job or post an open position on the official Drupal community job board. Search or post Drupal Jobs →
Read more

Drupal 8.2.x | API reference | Drupal API

This site is an API reference for Drupal, ... Examples project (sample modules) API change notices; Drupal 8 API longer references; Search Drupal 8.2.x.
Read more

Installation von Modul funzt nicht | Drupal Center

hochgeladen (per FTP) und /sites/all/modules. Wenn ich dann in der Drupal Admin unter "modules" schaue erscheint es nicht in der Liste. b) ...
Read more

Drupal 6 Module | Drupal Center

Hier werden die gängigsten Drupal 6 Module, in den entsprechenden Kategorien, vorgestellt. Es wird beschrieben wofür sie da sind, wie man sie installiert ...
Read more

Drupal Einführung und wichtige Module | Drupal Berlin ...

, Ich hatte für Kollegen, die ihr erstes Drupal Projekt gemacht haben eine kleine Einführung gegeben. Diese stelle ich hier zu Verfügen. Weiter unten ...
Read more

Drupal

Klar definierten Coding-Standards stellen sicher, dass alle Drupal-Module in das Baukastensystem passen. ... Drupal ist sehr erfolgreich darin, ...
Read more

Drupal - Wikipedia, the free encyclopedia

Drupal / ˈ d r uː p əl / is a free and open-source content-management framework written in PHP and distributed under the GNU General Public License. It ...
Read more

Drupal und die sieben (wichtigsten) Module | Computerclub ...

Druckversion. Der Erfolg und die Popularität von Drupal beruhen nicht zuletzt auf der leichten Erweiterbarkeit des Systems durch Dritt-Module. Im Laufe ...
Read more