Module: Blacklight::ConfigurationHelperBehavior

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



7
8
9
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 7

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

#default_document_index_view_typeObject

Get the default index view type



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

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_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)


15
16
17
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 15

def default_search_field?(selected_search_field)
  selected_search_field.blank? || (blacklight_config.default_search_field && selected_search_field == blacklight_config.default_search_field[:key])
end

#default_sort_fieldObject

Default sort field



90
91
92
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 90

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



76
77
78
79
80
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 76

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:



69
70
71
72
73
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 69

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

#facet_field_label(field) ⇒ String

Look up the label for the facet field

Returns:

  • (String)


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

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)


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

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

  t(first, default: rest)
end

#label_for_search_field(key) ⇒ String

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

Returns:

  • (String)


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

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

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



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

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

#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)


109
110
111
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 109

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)


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

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