0

I have implemented hook_block_info() to define a block inside a custom module 'x'. I have followed the documentation and believe the values in my array are correct. I have cleared all caches multiple times. I have disabled and re-enabled my module. I have tried setting status to both 0 and 1.

What is strange is that if I place a DPM() inside the x_block_info_alter(), I can see the block as an array when I visit the admin page. However, in the actual block list, it's not there!

Is there something wrong with my code that I can't see?

function x_block_info() {
  $blocks['mname'] = array(
    'info' => t('Admin title'),
    'cache' => DRUPAL_NO_CACHE,
    'status' => 1,
  );
  return $blocks;
}
1

I had exactly the same thing: dpm() showing me my block on admin/structure/block, but no block actually appearing in the admin. Disabling, uninstalling and re-enabling the module where I defined my block then clearing cache worked for me.

  • This will likely work for some people but it never worked for me. – sheldonkreger Apr 1 '15 at 16:53
0

Do you have something like this in your module in addition to the function above?

function x_block_view($delta='') {
  $block = array();
  switch ($delta) {
    case 'mname':
      $block['subject'] = t('MName');
      $block['content'] = x_function_to_generate_block_content();
      break;
  }
  return $block;
}
0

The only thing that ended up working for me was removing the cache setting from the array. If anybody else runs into problems, I suggest stripping the array down to only the required values and seeing if it appears. Then, set the rest of the values you need in the UI. Sad, but it was the only solution which worked for me.

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.