3
votes

I'm trying to create a block that comes with a drupal module. I can't get it to show up in my block list. I tried a lof of different tutorials, even just copy paste and it still doesn't show up. Could it be anything in my drupal settings that stops my modules block from showing up? Or is there anything wrong in the code?

The module shows and is activated.

This is my code right now:

helicopter_contest_form.info I'm trying to create a block that comes with a drupal module. I can't get it to show up in my block list. I tried a lof of different tutorials, even just copy paste and it still doesn't show up. Could it be anything in my drupal settings that stops my modules block from showing up? Or is there anything wrong in the code?

The module shows and is activated.

This is my code right now:

helicopter_contest_form.info

;$Id$
name = Helicopter contest form
description = Block module with a contest form
core = 7.x
package = My modules
files[] = helicopter_contest_form.module

helicopter_contest_form.module

 /**
* Implements hook_block_info().
*/
function membercount_block_info() {
 $blocks = array ();

$blocks['count_members'] = array (
'info' => t('Count Members'),
'cache' => DRUPAL_NO_CACHE,
);

return $blocks;
}

/**
* Implements hook_block_view().
*/
function membercount_block_view($name) {

if ($name == 'count_members') {
$count = db_query('SELECT COUNT(uid) - 1 FROM {users}')->fetchField();

$content = format_plural($count, 'This site has 1 user.', 'This site has @count users.');

$block = array (
  'subject' => t('Members'),
  'content' => $content,
);

return $block;
 }
 }

On a sidenote, how do I indent all my code 4 spaces at once? I have to do it each row by hand, it also ruins my indenting...

2

2 Answers

4
votes

While implementing a hook you should replace "hook" in the hook name with your module's short name, so just change the name of your function from membercount_block_info to helicopter_contest_form_block_info (the same for "hook_block_view").

Also, there is actually no need to mention files[] = helicopter_contest_form.module in .info file because .module is required anyway.

2
votes

Try to adjust the code to be:

/**
 * Implements hook_block_info().
 * This hook declares what blocks are provided by the module.
 */
function helicopter_form_info() {
    $blocks = array(); // the added line.
    $blocks['helicopter_form'] = array(
        'info' => t('Helicopter'),
        'cache' => DRUPAL_CACHE_PER_ROLE,
    );
    return $blocks;
}

I know it is strange, but I had the same issue once and it worked after I added that line.