You are here

function custom_search_block_view_alter in Custom Search 7

Implements hook_block_view_alter(). Used to exclude Facet API searching for excluded types.

File

./custom_search.module, line 646
Bring customizations to the default search box

Code

function custom_search_block_view_alter(&$data, $block) {
  if ($block->module == 'facetapi') {
    $excluded_types = array_filter(variable_get('custom_search_' . variable_get('custom_search_delta', '') . 'node_types_excluded', array()));
    if (!empty($excluded_types) && isset($data['content']['bundle']) && is_array($data['content']['bundle']["#items"])) {
      foreach ($data['content']['bundle']["#items"] as $key => $item) {

        // Find the type in the link.
        preg_match('/<a(.*)href="(.*)bundle%3A(.*?)(&|")(.*)/', $item['data'], $matches);

        // Exclude it if not needed.
        if (!empty($matches) && in_array($matches[3], $excluded_types)) {
          unset($data['content']['bundle']["#items"][$key]);
        }
      }
    }
  }
}