Sha256: 5737c9929816393e2457d0e0e0426b5cd543e57f46ffa711b7c5d70963b9e039

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Hyrax
  module Forms
    ##
    # Represents an embargo for edit through a work. That is, this form can
    # be used to wrap a Work in order to capture state changes related only to
    # its embargo, ignoring the work's other fields.
    #
    # @note this supports the edit functionality of
    #   +EmbargoesControllerBehavior+.
    class WorkEmbargoForm < Hyrax::ChangeSet
      property :embargo, form: Hyrax::Forms::Embargo, populator: :embargo_populator, prepopulator: :embargo_populator
      property :embargo_history, virtual: true, prepopulator: proc { |_opts| self.embargo_history = model.embargo&.embargo_history }
      property :embargo_release_date, virtual: true, prepopulator: proc { |_opts| self.embargo_release_date = model.embargo&.embargo_release_date }
      property :visibility_after_embargo, virtual: true, prepopulator: proc { |_opts| self.visibility_after_embargo = model.embargo&.visibility_after_embargo }
      property :visibility_during_embargo, virtual: true, prepopulator: proc { |_opts| self.visibility_during_embargo = model.embargo&.visibility_during_embargo }

      def embargo_populator(**)
        self.embargo = Hyrax::EmbargoManager.embargo_for(resource: model)
      end

      ##
      # @return [String]
      def human_readable_type
        model.to_model.human_readable_type
      end

      ##
      # @return [ActiveModel::Name]
      def model_name
        model.to_model.model_name
      end

      ##
      # @return [String]
      def to_s
        [*model.title].join(' ')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/forms/hyrax/forms/work_embargo_form.rb
hyrax-5.0.4 app/forms/hyrax/forms/work_embargo_form.rb
hyrax-5.0.3 app/forms/hyrax/forms/work_embargo_form.rb
hyrax-5.0.2 app/forms/hyrax/forms/work_embargo_form.rb