From 65d23047acb3a0ad420f0d0b67dd3368bcb0c3fc Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 6 Dec 2023 15:08:12 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=81=20Add=20video=20embed=20to=20OER?= =?UTF-8?q?=20Work=20Type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit manually adds video embed to oer model and form files. TODO: figure out why including the VideoEmbedBehavior and the VideoEmbedForm modules don't work for OER. Issue: - https://github.com/scientist-softserv/palni-palci/issues/911 --- app/forms/hyrax/oer_form.rb | 4 ++-- app/models/oer.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/forms/hyrax/oer_form.rb b/app/forms/hyrax/oer_form.rb index 458c6b363..bf0c5b30d 100644 --- a/app/forms/hyrax/oer_form.rb +++ b/app/forms/hyrax/oer_form.rb @@ -16,7 +16,7 @@ class OerForm < Hyrax::Forms::WorkForm newer_version_id previous_version_id alternate_version_id related_item_id keyword date_created files visibility_during_embargo embargo_release_date visibility_after_embargo visibility_during_lease lease_expiration_date visibility_after_lease visibility - ordered_member_ids in_works_ids member_of_collection_ids admin_set_id abstract] + ordered_member_ids in_works_ids member_of_collection_ids admin_set_id abstract video_embed] self.terms -=%i[previous_version_id newer_version_id alternate_version_id related_item_id] self.required_fields = %i[title creator resource_type date_created audience education_level learning_resource_type discipline rights_statement] @@ -24,7 +24,7 @@ class OerForm < Hyrax::Forms::WorkForm delegate :related_members_attributes=, :previous_version, :newer_version, :alternate_version, :related_item, to: :model def secondary_terms - super - [:rendering_ids] + super - [:rendering_ids] + [:video_embed] end def self.build_permitted_params diff --git a/app/models/oer.rb b/app/models/oer.rb index 874bf0a84..fbe3a4076 100644 --- a/app/models/oer.rb +++ b/app/models/oer.rb @@ -22,6 +22,15 @@ class Oer < ActiveFedora::Base validates :learning_resource_type, presence: { message: 'You must select a learning resource type.' } validates :resource_type, presence: { message: 'You must select a resource type.' } validates :discipline, presence: { message: 'You must select a discipline.' } + # rubocop:disable Style/RegexpLiteral + validates :video_embed, + format: { + # regex matches only youtube & vimeo urls that are formatted as embed links. + with: /(http:\/\/|https:\/\/)(www\.)?(player\.vimeo\.com|youtube\.com\/embed)/, + message: "Error: must be a valid YouTube or Vimeo Embed URL." + }, + if: :video_embed? + # rubocop:enable Style/RegexpLiteral property :audience, predicate: ::RDF::Vocab::SCHEMA.EducationalAudience do |index| index.as :stored_searchable, :facetable @@ -107,6 +116,14 @@ class Oer < ActiveFedora::Base index.as :stored_searchable, :facetable end + property :video_embed, predicate: ::RDF::URI("https://atla.com/terms/video_embed"), multiple: false do |index| + index.as :stored_searchable + end + + def video_embed? + video_embed.present? + end + # This must be included at the end, because it finalizes the metadata # schema (by adding accepts_nested_attributes) include ::Hyrax::BasicMetadata