hook_block visibility

yo2lux - June 27, 2008 - 21:56

I have the following implementation of hook_block:

function goodreads_block($op='list', $delta=0, $edit=array()) {
  switch($op) {
    case 'list':
      $blocks[0]['info'] = t('Goodreads Bookshelf');
      $blocks[0]['visibility'] = 'forum';
      return $blocks;
    case 'view':
      $blocks['subject'] = t('On the Bookshelf');
      $blocks['content'] = t('Temporary content');
      return $blocks;
  }
}

Please tell me why $blocks[0]['visibility'] = 'forum'; don't set the visibility for hook_block? I don't see the visibility information in "Administer -> Site building -> Blocks -> Goodreads Bookshelf preference".

Thanks!

Block visibility

kuldip zala - June 28, 2008 - 03:44

Try with this

function goodreads_block($op='list', $delta=0, $edit=array()) {
switch($op) {
case 'list':
$blocks[0]['info'] = t('Goodreads Bookshelf');
$blocks[1]['info'] = 'forum';
return $blocks;
case 'view':
$blocks['subject'] = t('On the Bookshelf');
$blocks['content'] = t('Temporary content');
return $blocks;
}
}

What you do is the same

yo2lux - June 28, 2008 - 09:10

What you do is the same thing. I want to set the VISIBILITY not info!
See here how visibility form appear: http://img529.imageshack.us/img529/9900/46293643vp7.jpg

I need to set a value in hook_block() for visibility.

Any help please?

yo2lux - June 29, 2008 - 21:51

Any help please?

Hope you have gotten your answer

atuyo60 - July 25, 2008 - 18:26

I stumbled upon this as I was looking for what the visibility key does, but I think figured out the answer...

Add your condition as a string to $blocks[0]['pages'], this is basically the content of the textarea in the block configuration.

As for $blocks[0]['visibility'], this is the option under the "Show block on specific pages" heading:
0 = Show on every page except the listed pages.
1 = Show on only the listed pages.
2 = Show if the following PHP code returns TRUE (PHP-mode, experts only).

I found that putting php

giorgio79 - August 15, 2008 - 19:54

I found that putting php code inside $blocks[0]['pages'] and setting $blocks[0]['visibility'] to 3 did not really work so I implemented the logic in the module php code...

there could be a syntax

atuyo60 - August 16, 2008 - 16:02

there could be a syntax error with ur code..
there is no option 3 for $blocks[0]['visibility']
I think it should be 2 and I had it working for my module..

caching issues SOLVED

aloyr - June 13, 2009 - 23:38

giorgio79, I had the same issue you did and I fixed it by clearing the cache (via admin_menu or devel modules) and removing the block configuration from the blocks table. It has worked every time for me when I do that.

also note the previous comment that there is no visibility type 3.

perl -e 'print unpack(u,";8F4@=&AE(&-H86YG92P@=7-E(&1R=7!A;\"\$*");'

 
 

Drupal is a registered trademark of Dries Buytaert.