Sha256: 8530c51f2782140f736d0a6ff8e1efa6149f20009891e33250c690d1f74be0b4

Contents?: true

Size: 1.37 KB

Versions: 34

Compression:

Stored size: 1.37 KB

Contents

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

34 entries across 34 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.9.5 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.9.4 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.9.3 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.9.2 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.9.1 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.9.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.8.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.7.2 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.7.1 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.7.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.6.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.5.1 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.5.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.0.0.pre.beta2 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.4.1 app/forms/hyrax/forms/admin_set_form.rb
hyrax-3.0.0.pre.beta1 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.4.0 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.3.3 app/forms/hyrax/forms/admin_set_form.rb
hyrax-2.3.2 app/forms/hyrax/forms/admin_set_form.rb