Sha256: 650183add4ac2218ece00d793cf15bfdae8e7a084f01c93160f61e4bfd32ed1d

Contents?: true

Size: 1.39 KB

Versions: 25

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true
module Hyrax
  module Forms
    class AdminSetForm < Hyrax::Forms::CollectionForm
      self.model_class = AdminSet
      self.terms = [:title, :description, :thumbnail_id]

      # Cast any array values on the model to scalars.
      def [](key)
        return super if key == :thumbnail_id
        super.first
      end

      def permission_template
        @permission_template ||= begin
                                   template_model = PermissionTemplate.find_or_create_by(source_id: model.id)
                                   PermissionTemplateForm.new(template_model)
                                 end
      end

      def thumbnail_title
        return unless model.thumbnail
        model.thumbnail.title.first
      end

      class << self
        # This determines whether the allowed parameters are single or multiple.
        # By default it delegates to the model.
        def multiple?(_term)
          false
        end

        # Overriden to cast 'title' and 'description' to an array
        def sanitize_params(form_params)
          super.tap do |params|
            params['title'] = Array.wrap(params['title']) if params.key?('title')
            params['description'] = Array.wrap(params['description']) if params.key?('description')
          end
        end
      end

      private

      def member_work_ids
        model.member_ids
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/forms/hyrax/forms/admin_set_form.rb
hyrax-5.0.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-5.0.0.rc3 app/forms/hyrax/forms/admin_set_form.rb
hyrax-5.0.0.rc2 app/forms/hyrax/forms/admin_set_form.rb
hyrax-5.0.0.rc1 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.6.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-4.0.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-4.0.0.rc3 app/forms/hyrax/forms/admin_set_form.rb
hyrax-4.0.0.rc2 app/forms/hyrax/forms/admin_set_form.rb
hyrax-4.0.0.rc1 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.5.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-4.0.0.beta2 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.4.2 app/forms/hyrax/forms/admin_set_form.rb
hyrax-4.0.0.beta1 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.4.1 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.4.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.3.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.2.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.1.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.0.2 app/forms/hyrax/forms/admin_set_form.rb