Sha256: 883b342f818c04ed651fc21028111e5a5fda8c497609176feba932fde0ec8f5c

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

module Pageflow
  # Override theme options and upload theme files for an entry type on
  # a per account basis.
  #
  # @since 15.7
  class ThemeCustomization < ApplicationRecord
    belongs_to :site

    serialize :overrides, JSON
    serialize :selected_file_ids, JSON

    has_many :uploaded_files, class_name: 'ThemeCustomizationFile'

    # Options that were passed to [ThemeCustomizations#update].
    #
    # @return [Hash<Symbol, Object>]
    def overrides
      super&.deep_symbolize_keys || {}
    end

    # Theme customization files that have been assigned a role via
    # [ThemeCustomizations#update].
    #
    # @return [Hash<Symbol, ThemeCustomizationFile>]
    def selected_files
      selected_file_ids.compact.transform_values do |id|
        selected_files_by_id[id]
      end
    end

    # @api private
    def entry_type
      Pageflow.config.entry_types.find_by_name!(entry_type_name)
    end

    private

    def selected_file_ids
      super&.deep_symbolize_keys || {}
    end

    def selected_files_by_id
      @selected_files_by_id ||= uploaded_files.where(id: selected_file_ids.values).index_by(&:id)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pageflow-16.2.0 app/models/pageflow/theme_customization.rb
pageflow-16.1.0 app/models/pageflow/theme_customization.rb
pageflow-16.0.0 app/models/pageflow/theme_customization.rb