Hello,
I try to learn drupal module developpment. I want to make an "hello world" module. It's ok with block and ona page but only in a path. But i can't make it working on the first page. any help would be welcome.
thank you
/**
* Display help and module information
* @param section which section of the site we're displaying help
* @return help text for section
*/
function mfm_help($section) {
switch ($section) {
case 'admin/modules#description':
$output = t("This is My First Module Test. Base for an empty begenning. Output Hello World.)");
case 'admin/settings/mfm':
return t("You can set here the value for the My first Module");
break;
}
return $output;
}
/**
* Valid permissions for this module
* @return array An array of valid permissions for the onthisdate module
*/
function mfm_perm() {
return array('access content','admin mfm');
} // function onthisdate_perm()
/**
* Generate HTML for the mfm block
* @param $op What kind of information to retrieve about the block or blocks. Possible values:
* 'list': A list of all blocks defined by the module.
* 'configure': A configuration form.
* 'save': Save the configuration options.
* 'view': Information about a particular block.
* @param $delta Which block to return (not applicable if $op is 'list').
* @param $edit If $op is 'save', the submitted form data from the configuration form.
* @returns block HTML
*/
function mfm_block($op='list', $delta=0) {
// listing of blocks, such as on the admin/block page
if ($op == "list") {
$block[0]["info"] = t('My first Module');
} else {
// our block content
$block['subject'] = 'My first Module';
$block['content'] = variable_get("mfm_text", "Hello World");
}
return $block;
}
function mfm_settings() {
// only administrators can access this module
if (!user_access("admin mfm")) {
return message_access();
}
$output = form_textfield(t("Module Text"), "mfm_text",
variable_get("mfm_text", "Hello World"), 20, 50,"");
return $output;
}
/**
* print out the page
*
* this function loads up the front page and displays it
*
*/
function mfm_page() {
global $user;
$output = variable_get("mfm_text", "Hello World");
print theme('page', $output);
}
/**
* Implementation of hook_menu().
*
*/
function mfm_menu($may_cache) {
$items = array();
// This is the minimum information you can provide for a menu item.
$items[] = array('path' => '', 'title' => t('Ma Page MFM'),
'callback' => 'mfm_page',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
return $items;
}
Comments
Pretty straight foward
Change
'path' => '' to 'path' => 'mfm'
Then goto administer => settings
Change "Default front page" so the value is mfm
(In general, the value will correspond to a path in the _menu hook)
This should do the trick.
Small warning, if you have not set 'anonymous user' so they can access content for a node they will get an error. You can either set that (administer => users => configure => permission, look under node) or
change 'access' => user_access('access content')
to
'access' => true
(which will allow anyone to view the page regardless of there role)
Perfect !!
Thank you very much, it is just what i needed.