Sha256: 71248f0bfc7f11aa6ac5b367134846d2830727d59f248086be6c0ef2fe7b89a6

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 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 && 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 && blacklight_configuration.search_fields.key?(slug)

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
blacklight-spotlight-4.2.0 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.1.2 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.1.1 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.1.0 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.0.3 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.0.2 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.0.1 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-4.0.0 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-3.6.0.beta10 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-3.6.0.beta9 app/models/spotlight/custom_search_field.rb
blacklight-spotlight-3.6.0.beta8 app/models/spotlight/custom_search_field.rb