Sha256: f2841404ba358186443aee5c8afedf53309c9b2ce734b6ab6a10ccd46d3f0f1f

Contents?: true

Size: 1.03 KB

Versions: 16

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Spotlight
  # Exhibit-specific custom search fields
  class CustomSearchField < ApplicationRecord
    if Rails.version > '7.1'
      serialize :configuration, type: Hash, coder: YAML
    else
      serialize :configuration, Hash, coder: YAML
    end
    belongs_to :exhibit

    def label=(label)
      configuration['label'] = label

      update_blacklight_configuration_label label
    end

    def label
      conf = if slug && blacklight_configuration&.search_fields&.key?(slug)
               blacklight_configuration.search_fields[slug].reverse_merge(configuration)
             else
               configuration
             end
      conf['label']
    end

    protected

    def blacklight_configuration
      exhibit&.blacklight_configuration
    end

    def update_blacklight_configuration_label(label)
      return unless slug && blacklight_configuration&.search_fields&.key?(slug)

      blacklight_configuration.search_fields[slug]['label'] = label
      blacklight_configuration.save
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
blacklight-spotlight-5.0.0.pre.alpha3 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-5.0.0.pre.alpha2 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-5.0.0.pre.alpha1 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.7.1 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.7.0 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.6.1 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.6.0 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.5.0 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.4.0 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.3.6 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.3.5 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.3.4 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.3.3 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.3.2 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.3.1 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.3.0 app/models/spotlight/custom_search_field.rb