开发者

Module does not show up in blocks (6.x)

I have a module that I've activated, but it does not show up in the disabled blocks list.

The module is named "My Module"

Inside the my_module folder I have:

my_module.module

my_module.info

my_module.info:

name = My Module
description = My module descript开发者_如何学编程ion.
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;
            }
    }           
}
?>


You're not returning any values in your hook call. You'll need to return the array for it to be displayed. I also never tend to use break; when writing implementations of hook_block either.

Try removing the break; and adding return $block; at the end of both cases.

e.g

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

and

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;

I'm sure you've seen it, but this might be beneficial to others http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_block/6

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜