You are here

function apachesolr_multilingual_block in Apache Solr Multilingual 6

Same name and namespace in other branches
  1. 6.2 apachesolr_multilingual.module \apachesolr_multilingual_block()

Implements hook_block().

File

./apachesolr_multilingual.module, line 453
Multilingual search using Apache Solr.

Code

function apachesolr_multilingual_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $enabled_facets = apachesolr_get_enabled_facets('apachesolr_multilingual');
      $facets = apachesolr_multilingual_apachesolr_facets();

      // Add the blocks
      $blocks = array();
      foreach ($enabled_facets as $delta => $facet_field) {
        if (isset($facets[$delta])) {
          $blocks[$delta] = $facets[$delta] + array(
            'cache' => BLOCK_CACHE_PER_PAGE,
          );
        }
      }
      return $blocks;
    case 'view':
      if (apachesolr_has_searched()) {
        $response = apachesolr_static_response_cache();
        if (empty($response)) {
          return;
        }
        $query = apachesolr_current_query();
        $facets = apachesolr_multilingual_apachesolr_facets();
        switch ($delta) {
          case 'apachesolr_multilingual_language':
            if (!variable_get('apachesolr_multilingual_auto_language_filter', 0) || variable_get('apachesolr_multilingual_auto_language_filter', 0) && variable_get('apachesolr_multilingual_auto_language_filter_detachable', 0) && (count((array) $response->facet_counts->facet_fields->{$facets}[$delta]['facet_field']) > 1 || !empty($_GET['filters']) && strpos($_GET['filters'], 'language:') !== FALSE)) {
              return apachesolr_facet_block($response, $query, 'apachesolr_multilingual', $delta, $facets[$delta]['facet_field'], t('Filter by language'), 'apachesolr_search_language_name');
            }
            break;
        }
      }
      break;
    case 'configure':
      return apachesolr_facetcount_form('apachesolr_multilingual', $delta);
    case 'save':
      apachesolr_facetcount_save($edit);
      break;
  }
}