Is there any API to know if the block is empty? Basically what I'm trying to do is to hide/unset the block inside template_preprocess_page
.
Here is my currrent code:
if ($variables['page']['rail_full']) {
foreach ($variables['page']['rail_full'] as $keys => $blocks) {
if (isset($blocks['content']['#views_contextual_links_info'])) {
$name = (isset($blocks['content']['#views_contextual_links_info']['views_ui'])) ? $blocks['content']['#views_contextual_links_info']['views_ui']['view']->name : '';
$display_id = explode('-', $blocks['#block']->delta);
$block = views_get_view_result($name, $display_id[1]);
if (empty($block)) {
unset($variables['page']['rail_full'][$keys]);
}
}
}
}
But the above code always return a count
of 1
when I print $block
.
The below works fine but not a good solution. I want it to be dynamic in all block as possible.
if (!isset($variables['node']->field_author_favorite_links['en'])) {
unset($variables['page']['rail_full']['views_franchise_page-block_2']);
}
if (!isset($variables['node']->field_article_column['en'])) {
unset($variables['page']['rail_full']['views_franchise_page-block_3']);
}