2

I am building a fairly simple module, and I am trying to set up a block, but it doesn't appear. I can't figure out what is wrong with my code.

function quick_links_block_info() {
  $blocks['quick_links_staff'] = array(
    'info' => t('Quick Links'),
    'status' => 1,
  );
  return $blocks;
}

function quick_links_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'quick_links_staff':
      $block['subject'] = t('Quick Links');
      $block['content'] = quick_links_get_links();
      break;
  }
  return $block;
}


function quick_links_get_links($department = '') {
  return t('Hi');
}
1

5 Answers 5

2

Your implementation of the block hooks is wrong. Try the below:

function quick_links_block_info() {
  $blocks['quick_links_staff'] = array(
    'info' => t('Quick Links'),
    'status' => 1,
  );
  return $blocks;
}

function quick_links_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'quick_links_staff':
      $block['subject'] = t('Quick Links');
      $block['content'] = quick_links_get_links();
      break;
  }
  return $block;
}


function quick_links_get_links($department = '') {
  return t('Hi');
}

I've namespaced the block, and changed the status from TRUE to 1, as per the hook_block_info() docs. I've also removed the assignment of $delta, as this is passed through automatically.

REFERENCES

hook_block_info()

hook_block_view()

4
  • Thanks Chapa, I did figure out that I had to make the above changes but am still not seeing the block. I know the code is being reached, because I can output other things. Just not the block.. Nov 20, 2012 at 21:13
  • Did you assign the block to a region on the currently used theme?
    – apaderno
    Nov 28, 2012 at 7:01
  • This is the correct answer: If you define the block as $blocks['quick_links'], and then return its content when $delta is equal to 'staff', the block is not rendered.
    – apaderno
    Nov 28, 2012 at 7:03
  • Hi kiamlaluno, thanks for pointing it out. i did notice that I had to provide the same index used in $blocks to the $delta that and I fixed the code, but the block never showed up even after the fix. so i'm still confused/baffled Nov 28, 2012 at 18:41
2

I had the same problem, I cleared all caches under performance and my module showed up in blocks.

2
  • In this case, the problem is not the cache. The code used from the OP defines a block with an ID, and then outputs the block content when the block ID is another one.
    – apaderno
    Dec 15, 2012 at 22:29
  • Thats not the case at all! i fixed my code moments after posting it, and it still does not work. till this day.. Dec 27, 2012 at 20:19
0

Uninstall the Module and install the module again and you will be able to see the block that you have created.

0

Use:

'status' => 0

or

'status' => 1,

and provide a region like this:

'status' => 1,
'region' => 'footer',
0
0

Try the following:

  • double check your module is loaded properly and there are no typos,
  • you're testing it on the right environment:),
  • clear all caches (including memcached/redis) either in Performance or by drush cc all,
  • disable 'Cache blocks' (and other caches) in Performance
  • restart Apache server (it could be OPCache/XCache),
  • check if Apache user has read access to your module file or folder,
  • check logs (e.g. drush watchdog-show --tail),
  • install drush_extras and run: drush block-show to see if your block is on the list
  • see if the block is loadable either at /devel/php or via drush:

    drush ev "var_dump(block_load('foomodule', 'foodelta'));"
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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