Skip to content

Commit

Permalink
🧹 Create a module for video embed form
Browse files Browse the repository at this point in the history
This commit DRYs up repetitive code by creating a VideoEmbedFormBehavior module.
  • Loading branch information
Shana Moore committed Dec 6, 2023
1 parent 8d997e4 commit 4e8da4d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
7 changes: 2 additions & 5 deletions app/forms/hyrax/cdl_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ class CdlForm < Hyrax::Forms::WorkForm
self.model_class = ::Cdl
include HydraEditor::Form::Permissions
include PdfFormBehavior
include VideoEmbedFormBehavior
# List these terms first after the "Additional fields" divider
self.terms = %i[contributing_library library_catalog_identifier admin_note video_embed] + self.terms # rubocop:disable Style/RedundantSelf
self.terms = %i[contributing_library library_catalog_identifier admin_note] + self.terms # rubocop:disable Style/RedundantSelf
self.terms += %i[resource_type additional_information bibliographic_citation chronology_note]
self.terms -= %i[based_near]
self.required_fields = %i[title creator keyword rights_statement resource_type]

def secondary_terms
super + %i[video_embed]
end
end
end
7 changes: 2 additions & 5 deletions app/forms/hyrax/generic_work_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ class GenericWorkForm < Hyrax::Forms::WorkForm
self.model_class = ::GenericWork
include HydraEditor::Form::Permissions
include PdfFormBehavior
include VideoEmbedFormBehavior

self.terms = [:admin_note, :video_embed] + terms
self.terms = [:admin_note] + terms
self.terms += %i[resource_type additional_information bibliographic_citation]
self.required_fields = %i[title creator keyword rights_statement resource_type]

def secondary_terms
super + %i[video_embed]
end
end
end
7 changes: 2 additions & 5 deletions app/forms/hyrax/image_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ class ImageForm < Hyrax::Forms::WorkForm
include Hyrax::FormTerms
self.model_class = ::Image
include PdfFormBehavior
include VideoEmbedFormBehavior

self.terms = [:admin_note, :video_embed] + self.terms # rubocop:disable Style/RedundantSelf
self.terms = [:admin_note] + self.terms # rubocop:disable Style/RedundantSelf
self.terms += %i[resource_type extent additional_information bibliographic_citation]
self.required_fields = %i[title creator keyword rights_statement resource_type]

def secondary_terms
super + %i[video_embed]
end
end
end
13 changes: 13 additions & 0 deletions app/forms/video_embed_form_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_sting_literal: true

module VideoEmbedFormBehavior
extend ActiveSupport::Concern

included do
self.terms += %i[video_embed]
end

def secondary_terms
super + %i[video_embed]
end
end

0 comments on commit 4e8da4d

Please sign in to comment.