1

I tried to register two custom block in my custom_blocks module with the following code.

function custom_blocks_block_info(){
  $blocks = array();
  $blocks['featured_items'] = array(
    'info' => t('Featured Items'),
    'status' => TRUE
  );
  $blocks['workflow_illustration'] = array(
    'info' => t('How it works'),
    'status' => TRUE
  );
  return $blocks;
}

function custom_blocks_block_view($delta = ''){
  $block = array();
  switch ($delta) {
    case 'featured_items':
      $block['content'] = featured_items();
      break;
    case 'workflow_illustration':
      $block['content'] = workflow_chart();
      break;
  }
  return $block;    
}

But the problem is 'Featured Items' block is shown in the block administer page. But the 'How it Works' block is not shown (may be not registered :?) in the block administer page.

I tried deactivating the module >> clear drupal cache >> clear browser cache (?) >> activate the module again.

Still the 'Featured Block' is the only block showing up. Please help me to get my block accessible via block administer page.

  • May be the problem is in "workflow_chart()" function have you checked it? – Enxebre Sep 12 '13 at 11:44
  • No @Enxebre both featured_items() and workflow_chart() returning simple html output. something like return '<div class="class"><span>Something</span></div>"; – Gokul Gopala Krishnan Sep 12 '13 at 11:56
  • i suggest to try with a full inline content for testing – pico34 Sep 12 '13 at 12:04
  • The blocks should still be listed in the block administer page regardless of what is in the block content. I copied your block_info() function into a custom module and tried it, and the two blocks show up in my blocks administer page. So the question is what is different on your drupal installation – 4life Sep 12 '13 at 12:08
  • Is what you've got in the question an identical copy-paste of your code? If it is, I'd suspect you've made some changes to core/contrib modules, or have dev/alpha/beta versions of modules that mess with blocks in some way. The code in your question, copied and pasted exactly, works fine for me too. Both blocks show up. – Clive Sep 12 '13 at 12:12
1

First, try to provide $block['subject']. Second, omit status in hook_block_info implementation, it may cause problems when there is no region assigned.

| improve this answer | |
  • added $block['subject'] and removed the 'status' now hook_block_info just has 'info' => '' but still it's not working @Mołot – Gokul Gopala Krishnan Sep 12 '13 at 11:57
  • Molot is on the right track - hook_block_info needs to have $block["info"] set. This is the administrative title of the block. In hook_block_view, you need to set $block["subject"] and $block["content"] – Scott Joudry Sep 12 '13 at 22:57
1

Double check if:

  1. Module is enabled.
  2. Module is not duplicated and system table points to the right file:

    drush sqlq "SELECT * FROM system WHERE name = 'foo'"
    
  3. You cleared all caches (in Development/Performance).

Troubleshooting

  • Check if hook_block_info() is called after clearing caches (add exit('foo'); to see if that break the site). If it's not called, then:

    • check for typos,
    • restart external caches (such as memcached or redis) if in use,
    • restart Apache server (it could be OPCache/XCache)
  • use drush to see if the hook is called:

    drush cc all
    
  • install drush_extras (via drush dl drush_extras) and check if the block is on the list when running from CLI:

    drush block-show | less +/my_block
    
  • if you've Devel enabled, try load the block at /devel/php and check if does exist:

    print_r(block_load('foomodule', 'foodelta'), TRUE);
    
| improve this answer | |
0

I remove status from info block. disable the my module and click uninstall tab and did uninstall for same module. after disabling the module it comes in uninstall list. clear cache and it's working now.

changed code:

function module_block_info() {
 $blocks = array();
 $blocks['hnavigation'] = array(
   'info' => t('Homepage Naviagation'),
 );
 $blocks['hslider'] = array(
   'info' => t('Homepage Banner Slider'),
 );

 return $blocks;
}

Previous code :

function module_block_info() {
 $blocks = array();
 $blocks['hnavigation'] = array(
   'info' => t('Homepage Naviagation'),
   'status'=>1,
 );
 $blocks['hslider'] = array(
   'info' => t('Homepage Banner Slider'),
   'status'=>1,

 );

 return $blocks;
}
| improve this answer | |
0

If you're an eejit like me this can occur when you name a custom block something which matches a flagged #id tag in an adblocker.

| improve this answer | |

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.