Sha256: 7c37bdcaf2f1e166ff49425ae4c415672323d3a8a3a9def4bf39a2524e459a58

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

# Mix-in for Blacklight CatalogController
#
# 1) Adds search_field to the controller representing a CQL search. 
#    It comes from the SearchBuilderExtension.psuedo_search_field class
#    variable. It's configured to not show up ordinarily in the search type
#    select menu, or the advanced search choices either. 
#
# 2) Over-rides the default blacklight search_fields methods so that
#    when CQL search has been triggered, it'll be reflected in the
#    on-screen search select menu for search type, so the context
#    makes sense. 
#
module BlacklightCql::ControllerExtension
  extend ActiveSupport::Concern


  included do 
    self.blacklight_config.configure do |config|
      hash = BlacklightCql::SearchBuilderExtension.pseudo_search_field
      config.add_search_field hash[:key], hash
    end

    self.helper BlacklightCql::ControllerExtension::Helpers
  end

  module Helpers
    # Make sure the CQL pseudo-search_field is included in the 'select'
    # when we're displaying a CQL search, so the select makes sense. 
    def search_fields
      field = BlacklightCql::SearchBuilderExtension.pseudo_search_field
      
      if params[:q].blank? || params[:search_field] != field[:key]
        super
      else      
        super.clone.push([field[:label], field[:key]]).uniq
      end
    end
  end
  
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blacklight_cql-3.0.1 lib/blacklight_cql/controller_extension.rb
blacklight_cql-3.0.0 lib/blacklight_cql/controller_extension.rb