模块不显示在块中(6.x)

时间:2011-09-09 14:54:28

标签: drupal-6 drupal-modules block

我有一个已激活的模块,但它没有显示在禁用的阻止列表中。

该模块名为“我的模块”

在my_module文件夹中,我有:
my_module.module
my_module.info

my_module.info:

name = My Module
description = My module description.
core = 6.x
package = My Modules

my_module.module

<?php
function hook_block($op = 'list', $delta = 0, $edit = array()){
    switch ($op) {
        case 'list':
            $block = array();
            //List out all blocks you want to create here
            $block[0]["info"] = t('Display info'); 
            break;  
        case 'view':    
            switch ($delta) {
            case 0:
                     $block['subject'] = "ADMIN Header of the block";
                     global $user;
                     if(in_array('Site admin', array_values($user->roles) || $user->uid == 1)){

                    $block['content'] = "input form";
                    $block['subject'] = "Header of the block";
                }

            break;
            }
    }           
}
?>

1 个答案:

答案 0 :(得分:1)

你没有在钩子调用中返回任何值。您需要返回数组才能显示它。在编写hook_block的实现时,我也从不倾向于使用break;

尝试删除break;并在两种情况结束时添加return $block;

e.g

 case 'list':
        $block = array();
        //List out all blocks you want to create here
        $block[0]["info"] = t('Display info'); 
        return $block;  

case 'view':    
        switch ($delta) {
        case 0:
                 $block['subject'] = "ADMIN Header of the block";
                 global $user;
                 if(in_array('Site admin', array_values($user->roles) || $user->uid == 1)){

                $block['content'] = "input form";
                $block['subject'] = "Header of the block";
            }

        return $block;

我确定你已经看过了,但这可能对其他人http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_block/6

有益