Tuesday, October 8, 2013

Create a simple Drupal 7 module - Hello World page

A Drupal module is made at least by 2 elements :
  • a .info file
  • an other file (.php, .inc ?)

To choose a name for you module, don't forget those basic rules :
  • no capital letter
  • no special character (excepted _ underscore)

Your first .info file

A .info is in fact a your_module_name.info file.
Let's make in your example a drupal_test module.

name (mandatory)

The name of your module (with capital letters and spaces this time, if you want)
name = Drupal Test Module

description (recommended)

description = A super duper test module !

core (mandatory)

core = 7.x

files[]

The location of your (php ?) files
files[] = inc/example.php

The whole .info file 

name = Drupal Test Module
description = Provides a really neat widget for your site's sidebar.
core = 7.x
files[] =
inc/example.php
For Drupal 7, you can find all informations about .info files here:
https://drupal.org/node/542202

 Now the example.php file

 You can now edit your php file, located in /sites/all/modules/drupal_test/inc/example.php

We will make a simple "Hello World" test. We will
  • make a menu link (make shortcut like http://www.mywebsite.com/drupal_test/mylink)
  • create a basic content (your "Hello World")
in your example.php module, create a drupal_test_menu() function.
function drupal_test_menu() {
    $items['drupal_test/mylink'] = array(
      'page callback' => 'drupal_test_hello_world',
    );
    return $items;
  }
This part redirects http://www.mywebsite.com/drupal_test/mylink to your website, and calls the
drupal_test_hello_world()function.
function drupal_test_hello_world() {
    return array(
      '#markup' => '<p>Hello world</p>', 
    );
  }
 That's it !

If you have questions, i'll try to answer you. Do not hesitate to leave comments.

17 comments:

  1. You explain well for "Create simple drupal 7 module". I'm dedicated Drupal developer and always read the article about whats happening in Drupal.

    ReplyDelete
  2. less than one dollar web hosting Domain hosting can be hit and miss when it comes to finding it cheap. Don’t get me wrong there are cheap web hosting options, but how about “super cheap and affordable” web hosting. Less than a dollar is “truly” affordable web hosting and this is a chance to get access to web hosting that is consistent and reliable when it comes to affordable web hosting.

    ReplyDelete
  3. BUY SPOTIFY PLAYS REAL PLAYS TO BOOST YOUR MUSIC.
    We will promote your tracks and give you very good promotion Buy spotify plays

    ReplyDelete
  4. Breaking News Today OIBNews is India's leading network by NDTV and CNN contributors. It has been serving the best out of the mess from World and India.

    ReplyDelete
  5. baanpolball บ้านผลบอล (baanpolball) อัพเดทตลอด 24 ชั่วโมง ราคาบอลวันนี้ วิเคราะห์บอลแม่น ฟรีๆ ทุกคู่ 100% ทีเด็ดบอลวันนี้ 4 คู่ ราคาบอลไหล แบบเรียลไทม์

    ReplyDelete
  6. Blue Xanax
    What Does Xanax Do? Firstly, Xanax is a trusted and widely used medication to help those who suffer from long term or chronic stress and anxiety. xanax 1mg

    ReplyDelete
  7. Casinos Now Compare the best legit online casinos that pay real money including the best crypto casinos, best mobile casinos and the best online casinos in 2021

    ReplyDelete
  8. ompare the best legit online casinos that pay real money including the best cry superslot

    ReplyDelete