Closed (fixed)
Project:
Block Node Visibility
Version:
6.x-1.0
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Reporter:
Created:
2 Jan 2012 at 19:28 UTC
Updated:
2 Jan 2012 at 20:05 UTC
Howdy,
I wanted to restrict a block to display on both all nodes of a specific content type, and on a specific view page.
Since block_node_visibility doesn't play nicely with page-specific visibility settings, I decided to implement hook_block_node_visibility in a helper module, to add views to the list of options.
Here's an example of programmatically adding all views pages to the list of block_node_visibilty checkboxes:
function example_helper_block_node_visibility($op, $types = array(), $node = NULL) {
switch ($op) {
case 'type':
$views_options = array();
$views = views_get_all_views();
foreach ($views as $view) {
if (! $view->disabled) {
foreach ($view->display as $display) {
if ($display->display_plugin == 'page'
// exclude administrative views
&& strpos($display->display_options['path'], 'admin/') !== 0) {
// prepend 'view_' to the index to avoid collision when a content type and a view path have the same name
$index = 'view_' . $display->display_options['path'];
$name = 'View: ' . $display->display_title;
$views_options[$index] = $name;
}
}
}
}
return array($views_options);
break;
case 'visibility':
foreach ($types as $type) {
if (strpos($type, 'view_') === 0) {
// remove prepended 'view_'
$type = substr($type, 5);
if (strpos($_GET['q'], $type) === 0) {
return TRUE;
}
}
}
return FALSE;
break;
}
}