Sha256: 74654e38ba5d62e0b36464c8ab5df7b1f6c470f063b12b42430187a25ee2ec52

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Blacklight
  module Hierarchy
    class QfacetValueComponent < ::ViewComponent::Base
      def initialize(field_name:, item:, id: nil, suppress_link: false)
        @field_name = field_name
        @item = item
        @id = id
        @suppress_link = suppress_link
      end

      attr_reader :field_name, :item, :id, :suppress_link

      def label_value
        return item.value if facet_item_presenter_class == Blacklight::FacetItemPresenter
        facet_item_presenter_class.new(item.qvalue, facet_config, helpers, field_name).label
      end

      def path_for_facet
        facet_item_presenter_class.new(item.qvalue, facet_config, helpers, field_name).href
      end

      def render_facet_count
        classes = "facet-count"
        content_tag("span", t('blacklight.search.facets.count', number: number_with_delimiter(item.hits)), class: classes)
      end

      def facet_config
        helpers.facet_configuration_for_field(field_name)
      end

      def hierarchy_config
        helpers.blacklight_config.facet_display[:hierarchy]
      end

      def field_name_prefix
        @field_name_prefix ||= field_name.gsub("_#{field_name.split(/_/).last}", '')
      end

      def facet_item_presenter_class
        hierarchy_config.dig(field_name_prefix)[2] || Blacklight::FacetItemPresenter
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blacklight-hierarchy-6.4.0 app/components/blacklight/hierarchy/qfacet_value_component.rb
blacklight-hierarchy-6.3.0 app/components/blacklight/hierarchy/qfacet_value_component.rb