Sha256: 0f80b6021311b6554ff4d0141c1788e86fffd54dd637894855fe402e766ea657

Contents?: true

Size: 1.59 KB

Versions: 27

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

module Spotlight
  # Mixin for adding default configuration to exhibits
  module ExhibitDefaults
    extend ActiveSupport::Concern

    included do
      before_create :build_home_page
      before_create :add_site_reference
      after_create :initialize_config
      after_create :initialize_browse
      after_create :initialize_main_navigation
      after_create :initialize_filter
    end

    protected

    def initialize_filter
      return unless Spotlight::Engine.config.filter_resources_by_exhibit

      filters.create field: default_filter_field, value: default_filter_value
    end

    def initialize_config
      self.blacklight_configuration ||= Spotlight::BlacklightConfiguration.create!
    end

    def initialize_browse
      return unless searches.blank?

      searches.create title: 'All Exhibit Items',
                      long_description: 'All items in this exhibit.'
    end

    def initialize_main_navigation
      default_main_navigations.each_with_index do |nav_type, weight|
        main_navigations.create nav_type: nav_type, weight: weight
      end
    end

    def add_site_reference
      self.site ||= Spotlight::Site.instance
    end

    def default_filter_field
      "#{Spotlight::Engine.config.solr_fields.prefix}spotlight_exhibit_slug_#{slug}#{Spotlight::Engine.config.solr_fields.boolean_suffix}"
    end

    # Return a string to work around any ActiveRecord type-casting
    def default_filter_value
      'true'
    end

    private

    def default_main_navigations
      Spotlight::Engine.config.exhibit_main_navigation.dup
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.rc1 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-3.0.0.alpha.10 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-3.0.0.alpha.9 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-3.0.0.alpha.8 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-3.0.0.alpha.7 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-3.0.0.alpha.6 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-3.0.0.alpha.5 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-3.0.0.alpha.4 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-3.0.0.alpha.3 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-3.0.0.alpha.2 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-3.0.0.alpha.1 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-2.13.0 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-2.12.1 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-2.12.0 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-2.11.0 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-2.10.0 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-2.9.0 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-2.8.0 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-2.7.2 app/models/concerns/spotlight/exhibit_defaults.rb
blacklight-spotlight-2.7.1 app/models/concerns/spotlight/exhibit_defaults.rb