5. Le code complet du module
Soumis par Didier Joly le Mercredi 25 septembre 2013
Après ces quelques explications, voici le code complet des deux fichiers du module Hello world.
Le fichier hello_world.info
name = Hello world
description = My first module for Drupal 7.
package = Drupal 7 Development
version = 7.x-0.x-dev
core = 7.x
files[] = hello_world.module
Ce fichier sera créé dans le répertoire ./sites/all/modules/custom/hello_world
.
Le fichier hello_world.module
/**
* @file
* A module exemplifying Drupal coding practices and APIs.
*
* This module provides a page that displays Hello World.
* It illustrates coding standards, practices, and API use for Drupal 7.
*/
/**
* Implements hook_help()
*/
function hello_world_help($path, $arg) {
if ($path == 'admin/help#hello_world') {
return t('A demonstration module.');
}
}
/**
* Implements hook_menu()
*/
function hello_world_menu() {
$items = array();
$items['hello-world/first'] = array(
'title' => t('First page'),
'description' => t('First page for Hello World module.'),
'page callback' => '_hello_world_first_page',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
'weight' => -10,
);
return $items;
}
/**
* Implements the function _hello_world_first_page()
*/
function _hello_world_first_page() {
return '<p>' . t('Hello world !') . '</p>';
}
Ce fichier sera créé dans le répertoire ./sites/all/modules/custom/hello_world
.
Fichier à télécharger: