-1

I'm trying to create the simplest block module possible. For the start, I want it to be visible on admin blocks page.

I've read few articles and browsed drupal block API and here is my code:

function module_block($op = 'list', $delta = 0, $edit = array()){
    switch($op){
        case 'list':
            $blocks["delta"] = array(
                'info' => t('Admin title on list')
            );
            return $blocks;
        case 'view':
            if($delta=="delta"){
                $block['subject'] = t('Default title');
                $block['content'] = module_get_html_function();
            }
            return $block;      
    }
}

This code is placed in my custom drupal module in sites/default/modules and it's enabled on admin modules page. Here's what i've done:

Save module file -> Clear cache -> Enable module -> Clear cache

But! I'm not able to see this Admin title on list block on my admin blocks page. Can you tell me what am i doing wrong ?

Any help would be appreciated

  • Is your custom modul really named "modul" or isn't this your actual code? – Berdir Dec 30 '11 at 14:13
  • no, my custom module is named vegspot. Does block module function needs to have vegspot_ prefix than ? – bajki Dec 30 '11 at 14:19
  • ok the problem was with function name, it should be modulename_block(), not anything_block() :) You've pointed this out, if you'll post an answer, i'll mark it as 'accepted' – bajki Dec 30 '11 at 14:31
3

Just like any hook implementation, hook_block() needs to be prefixed with the name of your module instead of module_. That's how Drupal finds them, by looping over every enabled module and checking if a corresponding function exists.

While not technically required, it is also strongly recommended to prefix all other functions of your module with the module name to prevent conflicts with other modules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.