Module: Blacklight::FacetsHelperBehavior

Extended by:
Deprecation
Includes:
Facet
Included in:
CatalogHelperBehavior
Defined in:
app/helpers/blacklight/facets_helper_behavior.rb

Instance Method Summary collapse

Methods included from Facet

#facet_by_field_name, #facet_paginator, #facets_from_request

Instance Method Details

#facet_display_value(field, item) ⇒ String

Deprecated.

Get the displayable version of a facet's value

Parameters:

  • field (Object)
  • item (String)

    value

Returns:

  • (String)


299
300
301
302
303
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 299

def facet_display_value field, item
  deprecated_method(:facet_display_value)
  facet_config = facet_configuration_for_field(field)
  facet_item_presenter(facet_config, item, field).label
end

#facet_field_id(facet_field) ⇒ Object

Deprecated.


306
307
308
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 306

def facet_field_id facet_field
  "facet-#{facet_field.key.parameterize}"
end

#facet_field_in_params?(field) ⇒ Boolean

Are any facet restrictions for a field in the query parameters?

Parameters:

  • field (String)

Returns:

  • (Boolean)


255
256
257
258
259
260
261
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 255

def facet_field_in_params? field
  config = facet_configuration_for_field(field)

  Deprecation.silence(Blacklight::SearchState) do
    search_state.has_facet? config
  end
end

#facet_field_presenter(facet_config, display_facet) ⇒ Object



189
190
191
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 189

def facet_field_presenter(facet_config, display_facet)
  (facet_config.presenter || Blacklight::FacetFieldPresenter).new(facet_config, display_facet, self)
end

#facet_in_params?(field, item) ⇒ Boolean

Deprecated.

Check if the query parameters have the given facet field with the given value.

Parameters:

  • field (String)
  • item (String)

    facet value

Returns:

  • (Boolean)


273
274
275
276
277
278
279
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 273

def facet_in_params?(field, item)
  config = facet_configuration_for_field(field)

  Deprecation.silence(Blacklight::SearchState) do
    search_state.has_facet? config, value: facet_value_for_facet_item(item)
  end
end

#facet_params(field) ⇒ Object

Deprecated.

Get the values of the facet set in the blacklight query string



285
286
287
288
289
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 285

def facet_params field
  config = facet_configuration_for_field(field)

  search_state.params.dig(:f, config.key)
end

#facet_partial_name(display_facet = nil) ⇒ String

The name of the partial to use to render a facet field. uses the value of the “partial” field if set in the facet configuration otherwise uses “facet_pivot” if this facet is a pivot facet defaults to 'facet_limit'

Returns:

  • (String)


181
182
183
184
185
186
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 181

def facet_partial_name(display_facet = nil)
  config = facet_configuration_for_field(display_facet.name)
  name = config.partial
  name ||= "facet_pivot" if config.pivot
  name || "facet_limit"
end

#has_facet_values?(fields = facet_field_names, response = nil) ⇒ Boolean

Deprecated.

Check if any of the given fields have values

Parameters:

  • fields (Array<String>) (defaults to: facet_field_names)

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 14

def has_facet_values? fields = facet_field_names, response = nil
  deprecated_method(:has_facet_values?)
  unless response
    Deprecation.warn(self, 'Calling has_facet_values? without passing the ' \
      'second argument (response) is deprecated and will be removed in Blacklight ' \
      '8.0.0')
    response = @response
  end
  Deprecation.silence(Blacklight::FacetsHelperBehavior) do
    Deprecation.silence(Blacklight::Facet) do
      facets_from_request(fields, response).any? { |display_facet| should_render_facet?(display_facet) }
    end
  end
end

#path_for_facet(facet_field, item, path_options = {}) ⇒ String

Deprecated.

Where should this facet link to?

Parameters:

Returns:

  • (String)


216
217
218
219
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 216

def path_for_facet(facet_field, item, path_options = {})
  facet_config = facet_configuration_for_field(facet_field)
  facet_item_presenter(facet_config, item, facet_field).href(path_options)
end

#render_facet_count(num, options = {}) ⇒ String

Deprecated.

Renders a count value for facet limits. Can be over-ridden locally to change style. And can be called by plugins to get consistent display.

Parameters:

  • num (Integer)

    number of facet results

  • options (Hash) (defaults to: {})

Options Hash (options):

  • an (Array<String>)

    array of classes to add to count span.

Returns:

  • (String)


244
245
246
247
248
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 244

def render_facet_count(num, options = {})
  deprecated_method(:render_facet_count)
  classes = (options[:classes] || []) << "facet-count"
  tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(num)), class: classes)
end

#render_facet_item(facet_field, item) ⇒ Object

Deprecated.

Renders a single facet item



131
132
133
134
135
136
137
138
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 131

def render_facet_item(facet_field, item)
  deprecated_method(:render_facet_item)
  if facet_in_params?(facet_field, item.value)
    render_selected_facet_value(facet_field, item)
  else
    render_facet_value(facet_field, item)
  end
end

#render_facet_limit(display_facet, options = {}) ⇒ String

Renders a single section for facet limit with a specified solr field used for faceting. Can be over-ridden for custom display on a per-facet basis.

Parameters:

Options Hash (options):

  • :partial (String)

    partial to render

  • :layout (String)

    partial layout to render

  • :locals (Hash)

    locals to pass to the partial

Returns:

  • (String)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 75

def render_facet_limit(display_facet, options = {})
  field_config = facet_configuration_for_field(display_facet.name)

  if field_config.component
    return unless should_render_field?(field_config, display_facet)

    component = field_config.component == true ? Blacklight::FacetFieldListComponent : field_config.component

    return render(
      component.new(
        facet_field: facet_field_presenter(field_config, display_facet),
        layout: (params[:action] == 'facet' ? false : options[:layout])
      )
    )
  end

  Deprecation.warn(Blacklight::FacetsHelperBehavior, 'Calling #render_facet_limit on a non-componentized'\
    ' facet is deprecated and will be removed in Blacklight 8')

  Deprecation.silence(Blacklight::FacetsHelperBehavior) do
    return unless should_render_facet?(display_facet, field_config)
  end
  options = options.dup

  Deprecation.silence(Blacklight::FacetsHelperBehavior) do
    options[:partial] ||= facet_partial_name(display_facet)
  end

  options[:layout] ||= "facet_layout" unless options.key?(:layout)
  options[:locals] ||= {}
  options[:locals][:field_name] ||= display_facet.name
  options[:locals][:facet_field] ||= field_config
  options[:locals][:display_facet] ||= display_facet

  render(options)
end

#render_facet_limit_list(paginator, facet_field, wrapping_element = :li) ⇒ Object

Deprecated.

Renders the list of values removes any elements where render_facet_item returns a nil value. This enables an application to filter undesireable facet items so they don't appear in the UI



117
118
119
120
121
122
123
124
125
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 117

def render_facet_limit_list(paginator, facet_field, wrapping_element = :li)
  facet_config ||= facet_configuration_for_field(facet_field)

  collection = paginator.items.map do |item|
    facet_item_presenter(facet_config, item, facet_field)
  end

  render(facet_item_component_class(facet_config).with_collection(collection, wrapping_element: wrapping_element))
end

#render_facet_partials(fields = nil, options = {}) ⇒ Object

Deprecated.

Render a collection of facet fields.

Parameters:

  • fields (Array<String>) (defaults to: nil)
  • options (Hash) (defaults to: {})

Options Hash (options):

Returns:

  • String

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 38

def render_facet_partials fields = nil, options = {}
  deprecated_method(:render_facet_partials)

  unless fields
    Deprecation.warn(self.class, 'Calling render_facet_partials without passing the ' \
      'first argument (fields) is deprecated and will be removed in Blacklight ' \
      '8.0.0')
    fields = facet_field_names
  end

  response = options.delete(:response)
  unless response
    Deprecation.warn(self.class, 'Calling render_facet_partials without passing the ' \
      'response keyword is deprecated and will be removed in Blacklight ' \
      '8.0.0')
    response = @response
  end
  Deprecation.silence(Blacklight::FacetsHelperBehavior) do
    Deprecation.silence(Blacklight::Facet) do
      safe_join(facets_from_request(fields, response).map do |display_facet|
        render_facet_limit(display_facet, options)
      end.compact, "\n")
    end
  end
end

#render_facet_value(facet_field, item, options = {}) ⇒ String

Standard display of a facet value in a list. Used in both _facets sidebar partial and catalog/facet expanded list. Will output facet value name as a link to add that to your restrictions, with count in parens.

Parameters:

Options Hash (options):

  • :suppress_link (Boolean)

    display the facet, but don't link to it

Returns:

  • (String)


203
204
205
206
207
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 203

def render_facet_value(facet_field, item, options = {})
  deprecated_method(:render_facet_value)
  facet_config = facet_configuration_for_field(facet_field)
  facet_item_component(facet_config, item, facet_field, **options).render_facet_value
end

#render_selected_facet_value(facet_field, item) ⇒ Object

Deprecated.

Standard display of a SELECTED facet value (e.g. without a link and with a remove button)

Parameters:

See Also:



229
230
231
232
233
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 229

def render_selected_facet_value(facet_field, item)
  deprecated_method(:render_selected_facet_value)
  facet_config = facet_configuration_for_field(facet_field)
  facet_item_component(facet_config, item, facet_field).render_selected_facet_value
end

#should_collapse_facet?(facet_field) ⇒ Boolean

Deprecated.

Determine whether a facet should be rendered as collapsed or not.

- if the facet is 'active', don't collapse
- if the facet is configured to collapse (the default), collapse
- if the facet is configured not to collapse, don't collapse

Parameters:

Returns:

  • (Boolean)


167
168
169
170
171
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 167

def should_collapse_facet? facet_field
  Deprecation.silence(Blacklight::FacetsHelperBehavior) do
    !facet_field_in_params?(facet_field.key) && facet_field.collapse
  end
end

#should_render_facet?(display_facet, facet_config = nil) ⇒ Boolean

Deprecated.

Determine if Blacklight should render the display_facet or not

By default, only render facets with items.

Parameters:

Returns:

  • (Boolean)


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

def should_render_facet? display_facet, facet_config = nil
  return false if display_facet.items.blank?

  # display when show is nil or true
  facet_config ||= facet_configuration_for_field(display_facet.name)
  should_render_field?(facet_config, display_facet)
end