Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

I102 valkyrie validations #2148

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/change_sets/generic_work_resource_change_set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true
require 'title_validator'

class GenericWorkResourceChangeSet < Hyrax::ChangeSet
property :title, multiple: true, required: true

# validating change_sets => https://github.com/samvera/valkyrie/wiki/Validating-change-sets
validates :title, presence: true
validates_with TitleValidator
end
10 changes: 10 additions & 0 deletions app/change_sets/image_resource_change_set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true
require 'title_validator'

class ImageResourceChangeSet < Hyrax::ChangeSet
property :title, multiple: true, required: true

# validating change_sets => https://github.com/samvera/valkyrie/wiki/Validating-change-sets
validates :title, presence: true
validates_with TitleValidator
end
9 changes: 9 additions & 0 deletions app/validators/title_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
class TitleValidator < ActiveModel::Validator
# ensure the property exists and is in the controlled vocabulary
def validate(record)
record.title.present?

record.errors.add :title, 'Your work must have a title.'
end
end
Loading