-
Notifications
You must be signed in to change notification settings - Fork 138
Customizing Metadata
The GenericFile class is provided by Sufia, but we want to update the model with our own metadata so we define it in our app to override what Sufia provides. Since Rails finds the class in our local application, it won't load it from Sufia.
# app/models/generic_file.rb
class GenericFile < ActiveFedora::Base
include Sufia::GenericFile
endAdd the property declaration into the GenericFile class (and pass a block to make sure the property is indexed in Solr):
property :alternative, predicate: ::RDF::DC.alternative do |index|
index.as :stored_searchable, :facetable
endWhen you're done the file should look like this:
# app/models/generic_file.rb
class GenericFile < ActiveFedora::Base
include Sufia::GenericFile
property :alternative, predicate: ::RDF::DC.alternative
endWe create a subclass of the presenter adding alternative to the list of terms
# app/presenters/my_generic_file_presenter.rb
class MyGenericFilePresenter < Sufia::GenericFilePresenter
self.terms = [:resource_type, :title, :creator, :contributor, :description,
:tag, :rights, :publisher, :date_created, :subject, :language,
:identifier, :based_near, :related_url, :alternative]
end# app/controllers/generic_files_controller.rb
class GenericFilesController < ApplicationController
include Sufia::Controller
include Sufia::FilesControllerBehavior
self.presenter_class = MyGenericFilePresenter
endNow the fields show up in the show view, but we also want them on our edit form too. Let's create an edit form that has our field
This form will extend the presenter we already created.
# app/forms/my_file_edit_form.rb
class MyFileEditForm < MyGenericFilePresenter
include HydraEditor::Form
include HydraEditor::Form::Permissions
self.required_fields = [:title, :creator, :tag, :rights]
endCreate a batch form
# app/forms/my_batch_edit_form.rb
class MyBatchEditForm < MyFileEditForm
endAdd the following line to app/controllers/generic_files_controller.rb
self.edit_form_class = MyFileEditFormThe whole file should look like this:
class GenericFilesController < ApplicationController
include Sufia::Controller
include Sufia::FilesControllerBehavior
self.presenter_class = MyGenericFilePresenter
self.edit_form_class = MyFileEditForm
endAnd add the following line to app/controllers/batch_controller.rb
self. edit_form_class = MyFileEditFormThe whole file should look like this:
# app/controllers/batch_controller.rb
class BatchController < ApplicationController
include Sufia::BatchControllerBehavior
self.edit_form_class = MyBatchEditForm
endTODO
TODO
By default the label for the field in the form is taken from the property label, with the initial letter capitalised. Here is an example of customising it, and the associated help text:
# config/locales/sufia.en.yml
en:
simple_form:
labels:
generic_file:
alternative: "Alternative Title"
metadata_help:
generic_file:
alternative: "An alternative name for a file."TODO (I assume there is a different way of handling the label in the batch form?)