@@ -155,16 +155,28 @@ def get_form_block(self):
155155 :return: The ``wagtail.blocks.StructBlock`` to be used in the StreamField
156156 """
157157 return blocks .StructBlock (
158- [
159- ("label" , blocks .CharBlock ()),
160- ("help_text" , blocks .CharBlock (required = False )),
161- ("required" , blocks .BooleanBlock (required = False )),
162- ("default_value" , blocks .CharBlock (required = False )),
163- ],
158+ self .get_local_blocks (),
164159 icon = self .icon ,
165160 label = self .label ,
166161 )
167162
163+ def get_local_blocks (self ):
164+ """The blocks that should be added to the StructBlock for this field.
165+
166+ Override this to add blocks to, or remove blocks from, the StructBlock
167+ before it is instantiated. This is useful because adding blocks to the
168+ StructBlock after instantiation requires mucking with the StructBlock's
169+ internal, undocumented API.
170+
171+ :return: A list of tuples containing the block name and block instance.
172+ """
173+ return [
174+ ("label" , blocks .CharBlock ()),
175+ ("help_text" , blocks .CharBlock (required = False )),
176+ ("required" , blocks .BooleanBlock (required = False )),
177+ ("default_value" , blocks .CharBlock (required = False )),
178+ ]
179+
168180
169181class HookMultiSelectFormField (forms .MultipleChoiceField ):
170182 widget = forms .CheckboxSelectMultiple
0 commit comments