[development] How to disable any block or sidebar from module
Owen Barton
drupal at owenbarton.com
Fri Jul 17 19:01:21 UTC 2009
Here is some code that does a similar thing in preprocess page, to allow you
to override the entire sidebar with a CCK text field (if non-empty). You
could equally just conditionally unset($vars['right']) instead here.
function MYTHEME_preprocess_page(&$vars, $hook) {
// The Right Sidebar override uses a CCK field which, when populated,
replaces the right sidebar instead of the existing
// sidebar right content.
if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2) &&
isset($vars['node']->field_right_sidebar_override[0])) {
$trimmed =
trim(strip_tags($vars['node']->field_right_sidebar_override[0]['safe'],
'<img>'));
if (!empty($trimmed)) {
$vars['right'] =
$vars['node']->field_right_sidebar_override[0]['safe'];
}
}
}
- O
On Fri, Jul 17, 2009 at 11:56 AM, Steve Edwards <killshot91 at comcast.net>wrote:
> What about using a preprocess function in a module to unset the sidebar
> region variable if the condition is met?
>
> Steve
>
> Khalid Baheyeldin wrote:
>
>
>
> On Fri, Jul 17, 2009 at 2:01 PM, Earnie Boyd <earnie at users.sourceforge.net
> > wrote:
>
>> Quoting "Tomá? Fülöpp (vacilando.org)" <tomi at vacilando.org>:
>>
>> Hi,
>>>
>>> I cannot find a generic way how to disable a sidebar programmatically.
>>>
>>> In my module, if some conditions are met, I would like to make sure that
>>> the
>>> whole sidebar (or any blocks in it) are not rendered at all, regardless
>>> of
>>> the theme.
>>>
>>> Could somebody advise, please? Sorry if it's obvious..
>>>
>>>
>> I think you want to use hook_block()[1].
>>
>> [1] http://api.drupal.org/api/function/hook_block
>>
>
> He is talking about the whole sidebar, hence a region, not a block.
> hook_block() will not help here.
>
> In the past we have done it by setting the visibility PHP code for each
> block
> in a given region, and that would make the entire sidebar invisible if the
> conditions are met. It is a pain if you have more than a few blocks in that
> region (right side bar for example).
>
> You said you don't want it in the theme, but it would be a simple change in
> page.tpl.php
>
> <?php if ($right): ?>
> <?php if (*!custom_visibility_function*()) ?>
> <div id="sidebar-right" class="sidebar">
> <?php print $right ?>
> </div>
> <?php endif; ?>
> <?php endif; ?>
>
> The other option is to use preprocess_block(). Perhaps something like this
> in
> template.php
>
> <?php
> function phptemplate_preprocess_block(&$variables) {
> if ($variables['block']->region = 'right') {
> if (!custom_visibility_function()) {
> unset($variables['block'];
> }
> }
> }
> ?>
>
> Still in the theme though.
>
>>
>>
>> --
>> Earnie
>> -- http://r-feed.com/ -- http://for-my-kids.com/
>> -- http://www.4offer.biz/ -- http://give-me-an-offer.com/
>>
>>
>
>
> --
> Khalid M. Baheyeldin
> 2bits.com, Inc.
> http://2bits.com
> Drupal optimization, development, customization and consulting.
> Simplicity is prerequisite for reliability. -- Edsger W.Dijkstra
> Simplicity is the ultimate sophistication. -- Leonardo da Vinci
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.drupal.org/pipermail/development/attachments/20090717/aa7c41b9/attachment.htm>
More information about the development
mailing list