Articles

Synapseindia drupal development-Writing Drupal 7 Modules

by Php development aPP article php
Drupal is an influential CMS right out of the crate. In any case let's be realistic. The genuine reason that Drupal has picked up such footing in the gathered PHP CMS space isn't on account of it is stacked with fancy odds and ends, but since it can be reached out in apparently unbounded routes through extra modules. Actually, there are well in excess of seven thousand modules accessible from Drupal.org. How can it be that Drupal appreciates such an abundance of client helped extra code? 

The answer is that Drupal's API (Application Programmer Interface) gives the brilliant blend of straightforwardness and force. Very nearly every period of Drupal's page building methodology can be captured and the information changed. Be that as it may compelling modules can in any case be composed in simply a couple of dozen lines of code. 

In the following few pages we are going to make a module sans preparation. We will construct a module utilizing the Block API – the framework used to produce square substance. The module we make in this article is going to give a square that shows the quantity of parts (client accounts) on the site. 

This is the means by which we will move ahead: 

We will make another module index 

At that point we will make a .data (spot insight) record to depict the module 

From here, we will make our essential .module (spot module) record and present Drupal programming 

Next, we will make several "piece snares" to characterize the practices of our new square 

Utilizing the organization interface, we will turn on our new module and empower the piece 

Essentials 

For this article, it is accepted that you have the accompanying: 

Essential PHP advancement learning 

A running Drupal 7 occasion with administrator access 

Access to the filesystem for your Drupal 7 occasion 

A code supervisor or PHP IDE 

To begin, you will require a working Drupal 7 example that you can get to as a manager. You will likewise need to have the capacity to make documents and indexes within that Drupal establishment. The samples in this article are carried out on a standard introduce of Drupal 7.0 with no helped modules. 

Making a Module 

Ordinarily, a Drupal module has at any rate these three pieces: 

A module index that contains all module documents 

A data document 

A module PHP code document 

We will call our module membercount. In Drupal speech, this name is known as the machine name on the grounds that it is the name Drupal (the machine) uses to reference the module. 

Since we have the machine name, we can make our module's index. The default area for extra modules is the locales/all/modules registry. In that index, we will make an envelope named with the module's machine name: membercount/. 

Within this index we will make two documents. The main record, which we will see in the accompanying area, will contain data about our module. The second one will contain the module's PHP source code. 

The .information File 

The primary document in our module is the .illumination record. Drupal uses the .illumination document to focus insights about the module, including whether the module can be introduced and what different modules it relies on. An .insight record is constantly named with the machine name of the module, so our module must be named membercount.info. 

The .illumination document contains a rundown of name/quality sets. This record isn't a specially appointed settings document where you can put any data that you wish. There are twelve orders that can be set within a module. We will be utilizing just the few that are needed. 

name = Member Count 

depiction = Provides a piece that demonstrates the quantity of parts. 

center = 7.x 

The name order is needed on the whole .insight records. Its design is to give an intelligible name for the module. 

The depiction mandate ought to have an one-sentence portrayal of what the module does. 

The following order, center, has an utilitarian part. Drupal alludes to this to verify that the module can be introduced. Endeavoring to introduce this module on a Drupal 6 framework, for instance, would produce a slip. 

Every one of the three of these orders are needed. 

Beginning the .module File 

The following record that we are going to make is the .module document, membercount.module. This document is naturally stacked by Drupal, which anticipates that the record will contain PHP code. Like .information records, the base name of a .module document is the module's machine name. 

Generally, Drupal modules are composed as procedural code. Regularly, the favored unit of association for Drupal code is the capacity. Our module record will have a three capacities in it. Here is the first: 

<?php 

/** 

* @file 

* The membercount module furnishes a square with part tally data. 

*/ 

/** 

* Implementation of hook_help(). 

*/ 

capacity membercount_help($path, $args) { 

on the off chance that ($path == 'administrator/help#membercount') { 

return t('to utilize this module, go to the square page and turn on the membercount block.'); 



There are several things that I will note in passing, yet which we don't have the space to look at all the more nearly. 

The principal is the <?php processor guideline. This is needed for any PHP documents. Note, on the other hand, that there is no end ?>. This is legitimate in PHP, as well as is viewed as a best practice for a document that is totally source code. It avoids blunders created by untimely cushion flushes. 

The second thing is that it takes after an extremely strict set of coding traditions. These traditions, portrayed at http://drupal.org/hub/360052, spread everything from indent profundity (two spaces, no tabs) to naming traditions (lowercase with underscores), administrators (one space on each one side), and remark styles. Drupal designers are required to take after these traditions with a specific end goal to boost the comprehensibility over the codebase. 

The following thing of note is the utilization of documentation pieces. Documentation squares are an uncommon sort of remark that starts with/** and closes with */. The motivation behind these areas is to give source code documentation that can be concentrated via mechanized instruments. Each PHP document ought to have a record level documentation square (which is hailed with the @file t

Sponsor Ads


About Php development aPP Freshman   article php

2 connections, 0 recommendations, 28 honor points.
Joined APSense since, November 19th, 2014, From haryana, India.

Created on Dec 31st 1969 18:00. Viewed 0 times.

Comments

No comment, be the first to comment.
Please sign in before you comment.