Hooks

wagtail_fedit.construct_adapter_toolbar

Construct the toolbar for the given adapter.
This is used to display the edit icon for the given adapter.

How it is called:

1items = [
2    FeditAdapterEditButton(),
3]
4for hook in hooks.get_hooks(CONSTRUCT_ADAPTER_TOOLBAR):
5    hook(items=items, adapter=adapter)

wagtail_fedit.register_type_renderer

Register a custom renderer for a type.

Example of how this type of renderer can be used:

1@hooks.register(REGISTER_TYPE_RENDERER)
2def register_renderers(renderer_map):
3
4    # This is a custom renderer for the Page model.
5    # It will render the Page model as a simple h2 tag.
6    renderer_map[Page] = lambda request, context, instance, value: format_html(
7        '<h2>{0}</h2>',
8        value.title
9    )

wagtail_fedit.register_css

Register a custom CSS file to be included when the utils.FEDIT_PREVIEW_VAR is set to True.

Example of how this hook is used in wagtail_hooks.py:

1@hooks.register(REGISTER_CSS)
2def register_css(request):
3    return [
4        format_html(
5            '<link rel="stylesheet" href="{0}">',
6            static('css/custom.css')
7        ),
8    ]

wagtail_fedit.field_editor_size

Control the size of the editor for the given model-field type.

Example of how this hook is called:

1for hook in hooks.get_hooks(FEDIT_FIELD_EDITOR_SIZE):
2    size = hook(model_instance, model_field)
3    if size:
4        return size

wagtail_fedit.register_js

Register a custom JS file to be included when the utils.FEDIT_PREVIEW_VAR is set to True.

This can be used to register custom adapter JS.

Example of how this hook is used in wagtail_hooks.py:

1@hooks.register(REGISTER_JS)
2def register_js(request):
3    return [
4        format_html(
5            '<script src="{0}"></script>',
6            static('js/custom.js')
7        ),
8    ]

wagtail_fedit.register_field_renderer

Register a custom renderer for a field.

Example of how this type of renderer is used in wagtail_hooks/renderers.py:

1@hooks.register(REGISTER_FIELD_RENDERER)
2def register_renderers(renderer_map):
3
4    # This is a custom renderer for RichText fields.
5    # It will render the RichText field as a RichText block.
6    renderer_map[RichTextField] =\
7        lambda request, context, instance, value: richtext(value)

wagtail_fedit.register_field_widgets

Register a custom widget for a field.

Example of how this hook is used in wagtail_hooks.py:

1@hooks.register(REGISTER_FIELD_WIDGETS)
2def register_field_widgets(widgets):
3    widgets[RichTextField] = AdminRichTextField
4    return widgets

Exclude the given model type from the related forms.
This is used internally to exclude the Page, Image, and Document models from the related forms.
This way; the user will have the actual widget for the field instead of the related form.

Example of how this hook is called and how it is used internally:

 1def use_related_form(field: models.Field) -> bool:
 2    for hook in hooks.get_hooks(EXCLUDE_FROM_RELATED_FORMS):
 3        if hook(field):
 4            return False
 5    return True
 6
 7
 8@hooks.register(EXCLUDE_FROM_RELATED_FORMS)
 9def exclude_related_forms(field):
10    if field.related_model in [Page, Image, Document]:
11        return True
12    return False

wagtail_fedit.action_menu_item_is_shown

Decide if the action menu item should be shown for the given instance.

Return None if you cannot decide, False if you want to hide the item, and True if you want to show the item.

Example of how this hook is called:

1for hook in hooks.get_hooks(ACTION_MENU_ITEM_IS_SHOWN):
2    result = hook(context, instance)
3    if result is not None:
4        return result # <- bool

wagtail_fedit.register_adapter_class

Register an adapter class with the adapter registry.

Example of how this hook is used in wagtail_hooks.py:

1@hooks.register(REGISTER_ADAPTER_CLASS)
2def register_adapter_class(registry):
3    registry.register(FieldAdapter)
4    registry.register(DomPositionedFieldAdapter)
5    registry.register(BlockAdapter)
6    registry.register(DomPositionedBlockAdapter)
7    registry.register(ModelAdapter)
8    registry.register(BackgroundImageFieldAdapter)

wagtail_fedit.register_adapter_urls

Register the adapter URLs.

Used internally by the URLMixin class.

Example of how this hook is used in wagtail_hooks.py:

1@hooks.register(REGISTER_ADAPTER_URLS)
2def register_adapter_urls():
3    return [
4        path("my-view/", views.MyView.as_view(), name="my_view")
5    ]