これは、Drupalモジュールを作成する最初の試みです:HelloWorld。
カスタムブロックとして表示する必要があります。これは、helloworldモジュール内の2つのDrupal7フック(hook_block_info()とhook_block_view())で実装できることがわかりました。Drupal 6では、非推奨のhook_block()が使用されていました。
実際の形式では機能しますが、テキストのみが表示されます:'これはマイモジュールであるブロックです'。私は実際に私のメイン関数の出力を表示する必要があります:helloworld_output()、t変数。
<?php
function helloworld_menu(){
$items = array();
//this is the url item
$items['helloworlds'] = array(
'title' => t('Hello world'),
//sets the callback, we call it down
'page callback' => 'helloworld_output',
//without this you get access denied
'access arguments' => array('access content'),
);
return $items;
}
/*
* Display output...this is the callback edited up
*/
function helloworld_output() {
header('Content-type: text/plain; charset=UTF-8');
header('Content-Disposition: inline');
$h = 'hellosworld';
return $h;
}
/*
* We need the following 2 functions: hook_block_info() and _block_view() hooks to create a new block where to display the output. These are 2 news functions in Drupal 7 since hook_block() is deprecated.
*/
function helloworld_block_info() {
$blocks = array();
$blocks['info'] = array(
'info' => t('My Module block')
);
return $blocks;
}
/*delta si used as a identifier in case you create multiple blocks from your module.*/
function helloworld_block_view($delta = ''){
$block = array();
$block['subject'] = "My Module";
$block['content'] = "This is a block which is My Module";
/*$block['content'] = $h;*/
return $block;
}
?>
今必要なのは、メイン関数の出力の内容を表示することです:helloworld_output()ブロック内:helloworld_block_view()。
$ block ['content'] = $ hが機能しない理由がわかりますか?手伝ってくれてありがとう。