Module: Blacklight::ConfigurationHelperBehavior

Extended by:
Deprecation
Included in:
CatalogHelperBehavior
Defined in:
app/helpers/blacklight/configuration_helper_behavior.rb

Instance Method Summary collapse

Instance Method Details

#active_sort_fieldsArray<Blacklight::Configuration::Field>

Return the available sort fields



18
19
20
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 18

def active_sort_fields
  blacklight_config.sort_fields.select { |_sort_key, field_config| should_render_field?(field_config) }
end

#constraint_query_label(localized_params = params) ⇒ String

Return a label for the currently selected search field. If no “search_field” or the default (e.g. “all_fields”) is selected, then return nil Otherwise grab the label of the selected search field.

Parameters:

  • localized_params (Hash) (defaults to: params)

    query parameters

Returns:

  • (String)


53
54
55
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 53

def constraint_query_label(localized_params = params)
  label_for_search_field(localized_params[:search_field]) unless default_search_field?(localized_params[:search_field])
end

#default_document_index_view_typeObject

Get the default index view type



165
166
167
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 165

def default_document_index_view_type
  document_index_views.select { |_k, config| config.respond_to?(:default) && config.default }.keys.first || document_index_views.keys.first
end

#default_per_pageObject

The default value for search results per page



206
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 206

delegate :default_per_page, to: :blacklight_config

#default_search_field?(selected_search_field) ⇒ Boolean

Is the search form using the default search field (“all_fields” by default)?

Parameters:

  • selected_search_field (String)

    the currently selected search_field

Returns:

  • (Boolean)


62
63
64
65
66
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 62

def default_search_field?(selected_search_field)
  Deprecation.silence(Blacklight::SearchFields) do
    selected_search_field.blank? || (default_search_field && selected_search_field == default_search_field[:key])
  end
end

#default_sort_fieldObject

Default sort field



200
201
202
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 200

def default_sort_field
  (active_sort_fields.find { |_k, config| config.respond_to?(:default) && config.default } || active_sort_fields.first)&.last
end

#document_index_view_controlsObject

filter #document_index_views to just views that should display in the view type control



157
158
159
160
161
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 157

def document_index_view_controls
  document_index_views.select do |_k, config|
    config.display_control.nil? || blacklight_configuration_context.evaluate_configuration_conditional(config.display_control)
  end
end

#document_index_viewsHash<Symbol => Blacklight::Configuration::ViewConfig>

Returns:



150
151
152
153
154
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 150

def document_index_views
  blacklight_config.view.select do |_k, config|
    should_render_field? config
  end
end

#document_show_field_label(document, field) ⇒ String

Deprecated.

Look up the label for the show field

Returns:

  • (String)


84
85
86
87
88
89
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 84

def document_show_field_label document, field
  field_config = blacklight_config.show_fields_for(document_presenter(document).display_type)[field]
  field_config ||= Blacklight::Configuration::NullField.new(key: field)

  field_config.display_label('show')
end

#document_show_fields(_document = nil) ⇒ Array<Blacklight::Configuration::Field>

used in the catalog/_show partial



42
43
44
45
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 42

def document_show_fields _document = nil
  Deprecation.warn(self, "document_show_fields is deprecated and will be removed in Blacklight 8. Use ShowPresenter#fields instead")
  blacklight_config.show_fields
end
Deprecated.

Used in the document list partial (search view) for creating a link to the document show action



187
188
189
190
191
192
193
194
195
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 187

def document_show_link_field document = nil
  fields = Array(blacklight_config.view_config(document_index_view_type).title_field)

  field = fields.first if document.nil?
  field ||= fields.find { |f| document.has? f }
  field &&= field&.to_sym

  field
end

#facet_field_label(field) ⇒ String

Look up the label for the facet field

Returns:

  • (String)


95
96
97
98
99
100
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 95

def facet_field_label field
  field_config = blacklight_config.facet_fields[field]
  field_config ||= Blacklight::Configuration::NullField.new(key: field)

  field_config.display_label('facet')
end

#labelString #labelString

Look up the label for a solr field.

Overloads:

  • #labelString

    Parameters:

    • an (Symbol)

      i18n key

  • #labelString

    Parameters:

    • default (String)

      label to display if the i18n look up fails

    • i18n (Symbol)

      keys to attempt to look up before falling back to the label

    • any (Symbol)

      number of additional keys

    • ... (Symbol)

Returns:

  • (String)


143
144
145
146
147
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 143

def field_label *i18n_keys
  first, *rest = i18n_keys.compact

  t(first, default: rest)
end

#has_alternative_views?Boolean

Check if there are alternative views configuration

Returns:

  • (Boolean)


172
173
174
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 172

def has_alternative_views?
  document_index_views.keys.length > 1
end

#index_field_label(document, field) ⇒ String

Deprecated.

Look up the label for the index field

Returns:

  • (String)


72
73
74
75
76
77
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 72

def index_field_label document, field
  field_config = blacklight_config.index_fields_for(document_presenter(document).display_type)[field]
  field_config ||= Blacklight::Configuration::NullField.new(key: field)

  field_config.display_label('index')
end

#index_fields(_document = nil) ⇒ Array<Blacklight::Configuration::Field>

Index fields to display for a type of document

Parameters:

Returns:



10
11
12
13
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 10

def index_fields _document = nil
  Deprecation.warn(self, "index_fields is deprecated and will be removed in Blacklight 8. Use IndexPresenter#fields instead")
  blacklight_config.index_fields
end

#label_for_search_field(key) ⇒ String

Shortcut for commonly needed operation, look up display label for the key specified.

Returns:

  • (String)


113
114
115
116
117
118
119
120
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 113

def label_for_search_field(key)
  field_config = blacklight_config.search_fields[key]
  return if key.nil? && field_config.nil?

  field_config ||= Blacklight::Configuration::NullField.new(key: key)

  field_config.display_label('search')
end

#per_page_options_for_selectObject

Deprecated.

The available options for results per page, in the style of #options_for_select



212
213
214
215
216
217
218
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 212

def per_page_options_for_select
  return [] if blacklight_config.per_page.blank?

  blacklight_config.per_page.map do |count|
    [t(:'blacklight.search.per_page.label', count: count).html_safe, count]
  end
end

#search_field_options_for_selectArray<Array>

Returns suitable argument to options_for_select method, to create an html select based on #search_field_list. Skips search_fields marked :include_in_simple_select => false

Returns:

  • (Array<Array>)

    the first element of the array is the label, the second is the sort field key



33
34
35
36
37
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 33

def search_field_options_for_select
  blacklight_config.search_fields.collect do |_key, field_def|
    [label_for_search_field(field_def.key), field_def.key] if should_render_field?(field_def)
  end.compact
end

#search_fieldsObject

Used in the search form partial for building a select tag



24
25
26
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 24

def search_fields
  search_field_options_for_select
end

#should_render_field?(field_config, *args) ⇒ Boolean

Determine whether to render a field by evaluating :if and :unless conditions

Parameters:

  • field_config (Blacklight::Solr::Configuration::Field)

Returns:

  • (Boolean)


226
227
228
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 226

def should_render_field?(field_config, *args)
  blacklight_configuration_context.evaluate_if_unless_configuration field_config, *args
end

#sort_field_label(key) ⇒ String

Returns:

  • (String)


123
124
125
126
127
128
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 123

def sort_field_label(key)
  field_config = blacklight_config.sort_fields[key]
  field_config ||= Blacklight::Configuration::NullField.new(key: key)

  field_config.display_label('sort')
end

#spell_check_maxNumber

Maximum number of results for spell checking

Returns:

  • (Number)


180
181
182
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 180

def spell_check_max
  blacklight_config.spell_max
end

#view_label(view) ⇒ String

Return the label for a search view

Returns:

  • (String)


104
105
106
107
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 104

def view_label(view)
  view_config = blacklight_config.view[view]
  view_config.display_label
end