Sha256: 2c1864905f3249cabea0f92911c21865fe5543ec10aac4d911a6ff479a43b292

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module Blacklight
  module Response
    # Render a group of facet fields
    class FacetGroupComponent < Blacklight::Component
      renders_one :body

      # @param [Blacklight::Response] response
      # @param [Array<Blacklight::Configuration::FacetField>] fields facet fields to render
      # @param [String] title the title of the facet group section
      # @param [String] id a unique identifier for the group
      def initialize(id:, title: nil, fields: [], response: nil)
        @groupname = id
        @id = id ? "facets-#{id}" : 'facets'
        @title = title || I18n.t("blacklight.search.#{@id}.title")
        @panel_id = id ? "facet-panel-#{id}-collapse" : 'facet-panel-collapse'

        # deprecated variables
        @fields = fields
        @response = response
      end

      # Provide fallback behavior for rendering this object without a body slot
      def before_render
        set_slot(:body, nil) { default_body } unless body
      end

      def render?
        body.present?
      end

      private

      # @deprecated
      def default_body
        Blacklight.deprecation.warn('Rendering the Blacklight::FacetGroupComponent without a body slot is deprecated.')
        helpers.render(Blacklight::FacetComponent.with_collection(@fields, response: @response))
      end

      # @deprecated
      def blacklight_config
        helpers.blacklight_config
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blacklight-8.0.0.beta1 app/components/blacklight/response/facet_group_component.rb