Sha256: 1fb995f063f66f7dd62ba1a0cb9d59f1010f699be9e585b772912052f5c212b6

Contents?: true

Size: 1.41 KB

Versions: 16

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module Blacklight
  class MetadataFieldComponent < Blacklight::Component
    with_collection_parameter :field

    # @param field [Blacklight::FieldPresenter]
    # @param layout [Blacklight::MetadataFieldLayoutComponent] alternate layout component to use
    # @param show [Boolean] are we showing only a single document (vs a list of search results); used for backwards-compatibility
    def initialize(field:, layout: nil, show: false, view_type: nil)
      @field = field
      @layout = layout || Blacklight::MetadataFieldLayoutComponent
      @view_type = view_type
      @show = show
    end

    def label
      if @show
        show_field_label @field.label('show')
      else
        index_field_label @field.label
      end
    end

    def render?
      @field.render_field?
    end

    ##
    # Render the index field label for a document
    #
    # Translations for index field labels should go under blacklight.search.fields
    # They are picked up from there by a value "%{label}" in blacklight.search.index.label
    # @return [String]
    def index_field_label label
      html_escape t(:"blacklight.search.index.#{@view_type}.label", default: :'blacklight.search.index.label', label: label)
    end

    ##
    # Render the show field label for a document
    #
    # @return [String]
    def show_field_label label
      t(:'blacklight.search.show.label', label: label)
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/components/blacklight/metadata_field_component.rb
blacklight-8.3.0 app/components/blacklight/metadata_field_component.rb
blacklight-8.2.2 app/components/blacklight/metadata_field_component.rb
blacklight-8.2.1 app/components/blacklight/metadata_field_component.rb
blacklight-8.2.0 app/components/blacklight/metadata_field_component.rb
blacklight-8.1.0 app/components/blacklight/metadata_field_component.rb
blacklight-8.0.1 app/components/blacklight/metadata_field_component.rb
blacklight-8.0.0 app/components/blacklight/metadata_field_component.rb
blacklight-8.0.0.beta8 app/components/blacklight/metadata_field_component.rb
blacklight-8.0.0.beta7 app/components/blacklight/metadata_field_component.rb
blacklight-8.0.0.beta6 app/components/blacklight/metadata_field_component.rb
blacklight-8.0.0.beta5 app/components/blacklight/metadata_field_component.rb
blacklight-8.0.0.beta4 app/components/blacklight/metadata_field_component.rb
blacklight-8.0.0.beta3 app/components/blacklight/metadata_field_component.rb
blacklight-8.0.0.beta2 app/components/blacklight/metadata_field_component.rb
blacklight-8.0.0.beta1 app/components/blacklight/metadata_field_component.rb