Class: Blacklight::SearchBarComponent
- Includes:
- ContentAreasShim
- Defined in:
- app/components/blacklight/search_bar_component.rb
Direct Known Subclasses
Instance Method Summary collapse
- #advanced_search_enabled? ⇒ Boolean
-
#autocomplete_path ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #autofocus ⇒ Object
-
#initialize(url:, params:, advanced_search_url: nil, presenter: nil, classes: ['search-query-form'], prefix: nil, method: 'GET', q: nil, query_param: :q, search_field: nil, search_fields: nil, autocomplete_path: nil, autofocus: nil, i18n: { scope: 'blacklight.search.form' }) ⇒ SearchBarComponent
constructor
rubocop:disable Metrics/ParameterLists.
- #search_fields ⇒ Object
Methods included from ContentAreasShim
Methods inherited from Component
Constructor Details
#initialize(url:, params:, advanced_search_url: nil, presenter: nil, classes: ['search-query-form'], prefix: nil, method: 'GET', q: nil, query_param: :q, search_field: nil, search_fields: nil, autocomplete_path: nil, autofocus: nil, i18n: { scope: 'blacklight.search.form' }) ⇒ SearchBarComponent
rubocop:disable Metrics/ParameterLists
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/components/blacklight/search_bar_component.rb', line 11 def initialize( url:, params:, advanced_search_url: nil, presenter: nil, classes: ['search-query-form'], prefix: nil, method: 'GET', q: nil, query_param: :q, search_field: nil, search_fields: nil, autocomplete_path: nil, autofocus: nil, i18n: { scope: 'blacklight.search.form' } ) @url = url @advanced_search_url = advanced_search_url @q = q || params[:q] @query_param = query_param @search_field = search_field || params[:search_field] @params = params.except(:q, :search_field, :utf8, :page) @prefix = prefix @classes = classes @method = method @autocomplete_path = autocomplete_path @autofocus = autofocus @search_fields = search_fields @i18n = i18n return if presenter.nil? Deprecation.warn(self, 'SearchBarComponent no longer uses a SearchBarPresenter, the presenter: param will be removed in 8.0. ' \ 'Set advanced_search.enabled, autocomplete_enabled, and enable_search_bar_autofocus on BlacklightConfiguration') end |
Instance Method Details
#advanced_search_enabled? ⇒ Boolean
62 63 64 |
# File 'app/components/blacklight/search_bar_component.rb', line 62 def advanced_search_enabled? blacklight_config.advanced_search.enabled end |
#autocomplete_path ⇒ Object
rubocop:enable Metrics/ParameterLists
39 40 41 42 43 |
# File 'app/components/blacklight/search_bar_component.rb', line 39 def autocomplete_path return nil unless blacklight_config.autocomplete_enabled @autocomplete_path end |
#autofocus ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'app/components/blacklight/search_bar_component.rb', line 45 def autofocus if @autofocus.nil? blacklight_config. && controller.is_a?(Blacklight::Catalog) && controller.action_name == "index" && !controller.has_search_parameters? else @autofocus end end |
#search_fields ⇒ Object
56 57 58 59 60 |
# File 'app/components/blacklight/search_bar_component.rb', line 56 def search_fields @search_fields ||= blacklight_config.search_fields.values .select { |field_def| helpers.should_render_field?(field_def) } .collect { |field_def| [helpers.label_for_search_field(field_def.key), field_def.key] } end |