You are here

function mefibs_block_info_alter in MEFIBS - More exposed forms in blocks 7

Implements hook_block_info_alter().

Add "Default block" to exposed filter blocks for mefibs enabled views.

File

./mefibs.module, line 293
Primarily Drupal hooks and global API functions to manipulate views and to provide an additional block with an exposed filter form.

Code

function mefibs_block_info_alter(&$blocks, $theme, $code_blocks) {

  // Avoid warnings in certain conditions, e.g. drush install
  // @see https://drupal.org/node/2229753
  if (!isset($blocks['views'])) {
    return;
  }
  foreach ($blocks['views'] as $delta => $block) {
    $start = microtime(TRUE);

    // if this is 32, this should be an md5 hash.
    if (strlen($delta) == 32) {
      $hashes = variable_get('views_block_hashes', array());
      if (!empty($hashes[$delta])) {
        $original_delta = $delta;
        $delta = $hashes[$delta];
      }
    }

    // This indicates it's a special one.
    if (substr($delta, 0, 1) == '-') {
      list($nothing, $type, $name, $display_id) = explode('-', $delta);

      // Put the - back on.
      $type = '-' . $type;
      if ($view = views_get_view($name)) {
        if ($view
          ->access($display_id)) {
          $view
            ->set_display($display_id);
          if (isset($view->display_handler)) {

            // Check if mefibs is configured
            if (!mefibs_display_is_mefibs_enabled($view->display_handler)) {
              continue;
            }

            // This is a default exposed filter bock for a view that has
            // mefibs enabled.
            // If $original_delta is set, we switch the delta value back to its
            // hashed version to store the info.
            if (!empty($original_delta)) {
              $delta = $original_delta;
            }
            $blocks['views'][$delta]['info'] .= ': Default Block';
          }
        }
        $view
          ->destroy();
      }
    }
  }
}