-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the Hyrax form API #6419
Conversation
28aa36c
to
1c014ac
Compare
Formerly, `Hyrax::Forms::ResourceForm` contained a bunch of shared behaviours between objects and filesets which weren’t appropriate for adminsets or collections. This commit splits those behaviours out into a new `Hyrax::ContainedInWorksBehavior` module, which allows all forms to inherit from the same base class.
Use `ResourceForm.for(resource: resource)` instead of `ResourceForm.for(resource)` to match `ValkyrieIndexer.for(resource: resource)` and other places in Hyrax code which require an explicit `resource` keyword argument. The old behaviour is still supported, but issues a deprecation warning.
1c014ac
to
5fa9035
Compare
@no-reply I’ve added a new commit to split up |
In discussion, it was decided that it was better to break this out into separate modules.
5fa9035
to
f698651
Compare
This PR contains three related changes aimed at polishing up the API of
Hyrax::Forms::ResourceForm
and related classes :—Make all of the core Valkyrie forms inherit from
Hyrax::Forms::ResourceForm
. The ones which didn’t previously areHyrax::Forms::PcdmCollectionForm
andHyrax::Forms::AdministrativeSetForm
. This required splitting off some of the existing behaviours which aren’t needed for collections into a separate module,Hyrax::ContainedInWorksBehavior
, which is included inHyrax::Forms::PcdmObjectForm
,Hyrax::Forms::FileSetForm
, andHyrax::Forms::ResourceBatchEditForm
.This module is a bit long and messy, and an alternative would be to have
Hyrax::Forms::PcdmObjectForm
,Hyrax::Forms::FileSetForm
, andHyrax::Forms::ResourceBatchEditForm
inherit from a subclass ofHyrax::Forms::ResourceForm
which defined those behaviours. But the module approach seemed more flexible.The module could also probably be broken down into more specific parts, but it seemed a bit unnecessary given that at this time all of the forms which include it require all of those behaviours.
Use
resource_class.pcdm_collection?
, etc, inHyrax::Forms::ResourceForm.for
instead ofresource_class <= Hyrax::PcdmCollection
. This offers more flexibility to Hyrax applications to define modules that aren’t strict subclasses of builtin Hyrax ones. Theif
checks are a bit complicated, because Hyrax recognizes two types of PCDM collection (AdministrativeSet
andPcdmCollection
), and two types of PCDM object (FileSet
and application‐defined model classes). The default is now to return a genericHyrax::Forms::ResourceForm
rather than aHyrax::Forms::PcdmObjectForm
since all application‐defined models should be returningtrue
forresource_class.pcdm_object?
; if an application has defined a resource which does not inherit fromHyrax::Work
, they may need to defineself.pcdm_object?
on their model classes.Change the API from
Hyrax::Forms::ResourceForm.for(_)
toHyrax::Forms::ResourceForm.for(resource:_)
. The former is still supported, with a deprecation warning. Most places in Hyrax code take aresource
argument as an explicit keyword argument, notablyHyrax::ValkyrieIndexer.for(resource:_)
which is a very similar API. I have always been bothered that forms do not follow this pattern, and pre‐5.0 seems like a good time to make the switch.