Additional Extension Points in FormBuilder and FormFieldStreamBlock
This change just refactors the code a bit by creating new methods to override when subclassing FormBuilder or FormFieldStreamBlock for customization:
- In
FormBuilder, created:create_field_classandcreate_field_name - In
FormFieldStreamBlock, created:instantiate_block - In
BaseField, created:get_local_blocks - In
BaseField, created:get_form_block_class - In
BaseField, created:get_form_block_kwargs
Please let me know if there's anything else I can do to help this get merged. If you need me to write tests, if you can you please let me know what the signature of each test should be, I will fill in the blanks.
Thanks!
Merged #170
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
02958f9) 95.65% compared to head (9a11923) 95.68%. Report is 84 commits behind head on master.
:exclamation: Current head 9a11923 differs from pull request most recent head 891b666. Consider uploading reports for the commit 891b666 to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## master #160 +/- ##
==========================================
+ Coverage 95.65% 95.68% +0.03%
==========================================
Files 28 28
Lines 943 951 +8
Branches 85 85
==========================================
+ Hits 902 910 +8
Misses 34 34
Partials 7 7
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@leongraumans I wonder if this PR is appropriate for merge? If this'll never be picked up, that's totally fine, please just let me know and I can continue to maintain this work in my fork. Thanks
Caught up to labd's master and added a new extension point: get_local_blocks()
@leongraumans I wonder if this PR is appropriate for merge? If this'll never be picked up, that's totally fine, please just let me know and I can continue to maintain this work in my fork. Thanks
bump, and thank you for maintaining this project!
Hi @rgs258,
Happy new year, and apologies for the late reply! I'll come back to you later this week.
Added yet another extension point, get_form_block_class, to allow the return of subclass of a structural block for further control over the block class, such as overriding the clean() method to provide custom validation.
I think I might share that we're using this package in a somewhat unconventional way. We've adapted it such that Pages themselves are the definition of the form. That is to say, we've made a subclass of Page for which the body StreamField has as local blocks all of the form elements registered to this package (in addition to the usual subclasses of FieldBlock). With this, an content author may create a page that itself is a form, and they may define that form inline with the page content. The Page, and the entire definition of the form, exist within the normal Wagtail system of revisions, permissions, workflow, previews (that was fun), etc.. This gives our content authors a great deal of freedom and allows out site to host ~2200 unique forms.
Its a dream of mine to extract the non proprietary parts of our adaptation and open source them as a bolt-on to this package. ...just got to find the time :)
Adjusted wagtailstreamforms/wagtailstreamforms_fields.py to use new self.get_form_block_class() and self.get_local_blocks() methods