Created
November 21, 2013 20:13
-
-
Save williamluisi/7588781 to your computer and use it in GitHub Desktop.
using hook_block_list_alter, programmatically hide/show a block on Views pgs and Node pages, based on if a flag field is set or not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_block_list_alter(). | |
*/ | |
function hook_block_list_alter(&$blocks) { | |
//dpm($blocks); | |
//check if pg is node | |
if (arg(0) == 'node') { | |
$nid = arg(1); | |
//load current node | |
if ($nid) { | |
$node = node_load($nid); | |
} | |
} | |
//views pg | |
else { | |
$views_page = views_get_page_view(); | |
if (is_object($views_page)) { | |
//get title of current view | |
$view_title = $views_page->name; | |
//get view | |
$view = views_get_view($view_title); | |
//get entity id from views header | |
$entity_id = $view->display['default']->display_options['header']['entity']['entity_id']; | |
if ($entity_id) { | |
//load node of entity in views header | |
$node = node_load($entity_id); | |
} | |
} | |
} | |
$field_value = $node->field['und'][0]['url']; | |
//unset block if $field_value empty | |
if (empty($field_value)) { | |
unset($blocks[620]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment