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');
}
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()

  • 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.. – mannadu Nov 20 '12 at 21:13
  • Did you assign the block to a region on the currently used theme? – kiamlaluno Nov 28 '12 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. – kiamlaluno Nov 28 '12 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 – mannadu Nov 28 '12 at 18:41
2

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

  • 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. – kiamlaluno Dec 15 '12 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.. – mannadu Dec 27 '12 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

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, privacy policy and cookie policy

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