|
@@ -5,8 +5,8 @@
|
|
|
On loading, Wagtail will search for any app with the file `wagtail_hooks.py` and execute the contents. This provides a way to register your own functions to execute at certain points in Wagtail's execution, such as when a page is saved or when the main menu is constructed.
|
|
|
|
|
|
```{note}
|
|
|
-Hooks are typically used to customise the view-level behaviour of the Wagtail admin and front-end.
|
|
|
-For customisations that only deal with model-level behaviour - such as calling an external service when a page or document is added - it is often better to use [Django's signal mechanism](inv:django#topics/signals) (see also: [Wagtail signals](signals)), as these are not dependent on a user taking a particular path through the admin interface.
|
|
|
+Hooks are typically used to customize the view-level behavior of the Wagtail admin and front-end.
|
|
|
+For customizations that only deal with model-level behavior - such as calling an external service when a page or document is added - it is often better to use [Django's signal mechanism](inv:django#topics/signals) (see also: [Wagtail signals](signals)), as these are not dependent on a user taking a particular path through the admin interface.
|
|
|
```
|
|
|
|
|
|
Registering functions with a Wagtail hook is done through the `@hooks.register` decorator:
|
|
@@ -104,13 +104,13 @@ depth: 1
|
|
|
|
|
|
## Admin modules
|
|
|
|
|
|
-Hooks for building new areas of the admin interface (alongside pages, images, documents and so on).
|
|
|
+Hooks for building new areas of the admin interface (alongside pages, images, documents, and so on).
|
|
|
|
|
|
(construct_homepage_panels)=
|
|
|
|
|
|
### `construct_homepage_panels`
|
|
|
|
|
|
-Add or remove panels from the Wagtail admin homepage. The callable passed into this hook should take a `request` object and a list of panel objects, and should modify this list in-place as required. Panel objects are [](template_components) with an additional `order` property, an integer that determines the panel's position in the final ordered list. The default panels use integers between `100` and `300`.
|
|
|
+Add or remove panels from the Wagtail admin homepage. The callable passed into this hook should take a `request` object and a list of panel objects and should modify this list in place as required. Panel objects are [](template_components) with an additional `order` property, an integer that determines the panel's position in the final ordered list. The default panels use integers between `100` and `300`.
|
|
|
|
|
|
```python
|
|
|
from django.utils.safestring import mark_safe
|
|
@@ -137,7 +137,7 @@ def add_another_welcome_panel(request, panels):
|
|
|
|
|
|
### `construct_homepage_summary_items`
|
|
|
|
|
|
-Add or remove items from the 'site summary' bar on the admin homepage (which shows the number of pages and other object that exist on the site). The callable passed into this hook should take a `request` object and a list of summary item objects, and should modify this list in-place as required. Summary item objects are instances of `wagtail.admin.site_summary.SummaryItem`, which extends [the Component class](creating_template_components) with the following additional methods and properties:
|
|
|
+Add or remove items from the 'site summary' bar on the admin homepage (which shows the number of pages and other object that exist on the site). The callable passed into this hook should take a `request` object and a list of summary item objects and should modify this list in-place as required. Summary item objects are instances of `wagtail.admin.site_summary.SummaryItem`, which extends [the Component class](creating_template_components) with the following additional methods and properties:
|
|
|
|
|
|
```{eval-rst}
|
|
|
.. method:: SummaryItem(request)
|
|
@@ -172,7 +172,7 @@ def hide_explorer_menu_item_from_frank(request, menu_items):
|
|
|
|
|
|
### `describe_collection_contents`
|
|
|
|
|
|
-Called when Wagtail needs to find out what objects exist in a collection, if any. Currently this happens on the confirmation before deleting a collection, to ensure that non-empty collections cannot be deleted. The callable passed to this hook will receive a `collection` object, and should return either `None` (to indicate no objects in this collection), or a dict containing the following keys:
|
|
|
+Called when Wagtail needs to find out what objects exist in a collection, if any. Currently, this happens on the confirmation before deleting a collection, to ensure that non-empty collections cannot be deleted. The callable passed to this hook will receive a `collection` object, and should return either `None` (to indicate no objects in this collection), or a dict containing the following keys:
|
|
|
|
|
|
- `count` - A numeric count of items in this collection
|
|
|
- `count_text` - A human-readable string describing the number of items in this collection, such as "3 documents". (Sites with multi-language support should return a translatable string here, most likely using the `django.utils.translation.ngettext` function.)
|
|
@@ -221,7 +221,7 @@ More details about the options that are available can be found at [](custom_acco
|
|
|
|
|
|
Add an item to the "More actions" tab on the "Account" page within the Wagtail admin.
|
|
|
The callable for this hook should return a dict with the keys
|
|
|
-`url`, `label` and `help_text`. For example:
|
|
|
+`url`, `label`, and `help_text`. For example:
|
|
|
|
|
|
```python
|
|
|
from django.urls import reverse
|
|
@@ -245,11 +245,11 @@ Add an item to the Wagtail admin menu. The callable passed to this hook must ret
|
|
|
- `name` - an internal name used to identify the menu item; defaults to the slugified form of the label.
|
|
|
- `icon_name` - icon to display against the menu item; no defaults, optional, but should be set for top-level menu items so they can be identified when collapsed.
|
|
|
- `classname` - additional classes applied to the link.
|
|
|
-- `order` - an integer which determines the item's position in the menu.
|
|
|
+- `order` - an integer that determines the item's position in the menu.
|
|
|
|
|
|
For menu items that are only available to superusers, the subclass `wagtail.admin.menu.AdminOnlyMenuItem` can be used in place of `MenuItem`.
|
|
|
|
|
|
-`MenuItem` can be further subclassed to customise its initialisation or conditionally show or hide the item for specific requests (for example, to apply permission checks); see the source code (`wagtail/admin/menu.py`) for details.
|
|
|
+`MenuItem` can be further subclassed to customize its initialization or conditionally show or hide the item for specific requests (for example, to apply permission checks); see the source code (`wagtail/admin/menu.py`) for details.
|
|
|
|
|
|
```python
|
|
|
from django.urls import reverse
|
|
@@ -356,7 +356,7 @@ As `construct_main_menu`, but modifies the 'Help' sub-menu rather than the top-l
|
|
|
|
|
|
### `register_admin_search_area`
|
|
|
|
|
|
-Add an item to the Wagtail admin search "Other Searches". Behaviour of this hook is similar to `register_admin_menu_item`. The callable passed to this hook must return an instance of `wagtail.admin.search.SearchArea`. New items can be constructed from the `SearchArea` class by passing the following parameters:
|
|
|
+Add an item to the Wagtail admin search "Other Searches". The behavior of this hook is similar to `register_admin_menu_item`. The callable passed to this hook must return an instance of `wagtail.admin.search.SearchArea`. New items can be constructed from the `SearchArea` class by passing the following parameters:
|
|
|
|
|
|
- `label` - text displayed in the "Other Searches" option box.
|
|
|
- `name` - an internal name used to identify the search option; defaults to the slugified form of the label.
|
|
@@ -370,7 +370,7 @@ Setting the URL can be achieved using reverse() on the target search page. The G
|
|
|
|
|
|
A template tag, `search_other` is provided by the `wagtailadmin_tags` template module. This tag takes a single, optional parameter, `current`, which allows you to specify the `name` of the search option currently active. If the parameter is not given, the hook defaults to a reverse lookup of the page's URL for comparison against the `url` parameter.
|
|
|
|
|
|
-`SearchArea` can be subclassed to customise the HTML output, specify JavaScript files required by the option, or conditionally show or hide the item for specific requests (for example, to apply permission checks); see the source code (`wagtail/admin/search.py`) for details.
|
|
|
+`SearchArea` can be subclassed to customize the HTML output, specify JavaScript files required by the option, or conditionally show or hide the item for specific requests (for example, to apply permission checks); see the source code (`wagtail/admin/search.py`) for details.
|
|
|
|
|
|
```python
|
|
|
from django.urls import reverse
|
|
@@ -425,7 +425,7 @@ def user_listing_external_profile(context, user):
|
|
|
|
|
|
### `filter_form_submissions_for_user`
|
|
|
|
|
|
-Allows access to form submissions to be customised on a per-user, per-form basis.
|
|
|
+Allows access to form submissions to be customized on a per-user, per-form basis.
|
|
|
|
|
|
This hook takes two parameters:
|
|
|
|
|
@@ -450,13 +450,13 @@ def construct_forms_for_user(user, queryset):
|
|
|
|
|
|
## Editor interface
|
|
|
|
|
|
-Hooks for customising the editing interface for pages and snippets.
|
|
|
+Hooks for customizing the editing interface for pages and snippets.
|
|
|
|
|
|
(register_rich_text_features)=
|
|
|
|
|
|
### `register_rich_text_features`
|
|
|
|
|
|
-Rich text fields in Wagtail work with a list of 'feature' identifiers that determine which editing controls are available in the editor, and which elements are allowed in the output; for example, a rich text field defined as `RichTextField(features=['h2', 'h3', 'bold', 'italic', 'link'])` would allow headings, bold / italic formatting and links, but not (for example) bullet lists or images. The `register_rich_text_features` hook allows new feature identifiers to be defined - see [](rich_text_features) for details.
|
|
|
+Rich text fields in Wagtail work with a list of 'feature' identifiers that determine which editing controls are available in the editor, and which elements are allowed in the output; for example, a rich text field defined as `RichTextField(features=['h2', 'h3', 'bold', 'italic', 'link'])` would allow headings, bold / italic formatting, and links, but not (for example) bullet lists or images. The `register_rich_text_features` hook allows new feature identifiers to be defined - see [](rich_text_features) for details.
|
|
|
|
|
|
(insert_global_admin_css)=
|
|
|
|
|
@@ -562,7 +562,7 @@ The `priority` argument controls the order the buttons are displayed in the drop
|
|
|
|
|
|
## Editor workflow
|
|
|
|
|
|
-Hooks for customising the way users are directed through the process of creating page content.
|
|
|
+Hooks for customizing the way users are directed through the process of creating page content.
|
|
|
|
|
|
(after_create_page)=
|
|
|
|
|
@@ -622,7 +622,7 @@ def before_create_page(request, parent_page, page_class):
|
|
|
|
|
|
### `after_delete_page`
|
|
|
|
|
|
-Do something after a `Page` object is deleted. Uses the same behaviour as `after_create_page`.
|
|
|
+Do something after a `Page` object is deleted. Uses the same behavior as `after_create_page`.
|
|
|
|
|
|
(before_delete_page)=
|
|
|
|
|
@@ -630,7 +630,7 @@ Do something after a `Page` object is deleted. Uses the same behaviour as `after
|
|
|
|
|
|
Called at the beginning of the "delete page" view passing in the request and the page object.
|
|
|
|
|
|
-Uses the same behaviour as `before_create_page`, is is run both for both `GET` and `POST` requests.
|
|
|
+Uses the same behavior as `before_create_page`, and is run for both `GET` and `POST` requests.
|
|
|
|
|
|
```python
|
|
|
from django.shortcuts import redirect
|
|
@@ -655,7 +655,7 @@ def before_delete_page(request, page):
|
|
|
|
|
|
### `after_edit_page`
|
|
|
|
|
|
-Do something with a `Page` object after it has been updated. Uses the same behaviour as `after_create_page`.
|
|
|
+Do something with a `Page` object after it has been updated. Uses the same behavior as `after_create_page`.
|
|
|
|
|
|
(before_edit_page)=
|
|
|
|
|
@@ -663,7 +663,7 @@ Do something with a `Page` object after it has been updated. Uses the same behav
|
|
|
|
|
|
Called at the beginning of the "edit page" view passing in the request and the page object.
|
|
|
|
|
|
-Uses the same behaviour as `before_create_page`.
|
|
|
+Uses the same behavior as `before_create_page`.
|
|
|
|
|
|
(after_publish_page)=
|
|
|
|
|
@@ -701,7 +701,7 @@ The function does not have to return anything, but if an object with a `status_c
|
|
|
|
|
|
### `after_copy_page`
|
|
|
|
|
|
-Do something with a `Page` object after it has been copied passing in the request, page object and the new copied page. Uses the same behaviour as `after_create_page`.
|
|
|
+Do something with a `Page` object after it has been copied passing in the request, page object, and the new copied page. Uses the same behavior as `after_create_page`.
|
|
|
|
|
|
(before_copy_page)=
|
|
|
|
|
@@ -709,21 +709,21 @@ Do something with a `Page` object after it has been copied passing in the reques
|
|
|
|
|
|
Called at the beginning of the "copy page" view passing in the request and the page object.
|
|
|
|
|
|
-Uses the same behaviour as `before_create_page`.
|
|
|
+Uses the same behavior as `before_create_page`.
|
|
|
|
|
|
(after_move_page)=
|
|
|
|
|
|
### `after_move_page`
|
|
|
|
|
|
-Do something with a `Page` object after it has been moved passing in the request and page object. Uses the same behaviour as `after_create_page`.
|
|
|
+Do something with a `Page` object after it has been moved passing in the request and page object. Uses the same behavior as `after_create_page`.
|
|
|
|
|
|
(before_move_page)=
|
|
|
|
|
|
### `before_move_page`
|
|
|
|
|
|
-Called at the beginning of the "move page" view passing in the request, the page object and the destination page object.
|
|
|
+Called at the beginning of the "move page" view passing in the request, the page object, and the destination page object.
|
|
|
|
|
|
-Uses the same behaviour as `before_create_page`.
|
|
|
+Uses the same behavior as `before_create_page`.
|
|
|
|
|
|
(before_convert_alias_page)=
|
|
|
|
|
@@ -762,17 +762,17 @@ We recommend they are non-aliased, direct translations of the pages from the fun
|
|
|
|
|
|
### `register_page_action_menu_item`
|
|
|
|
|
|
-Add an item to the popup menu of actions on the page creation and edit views. The callable passed to this hook must return an instance of `wagtail.admin.action_menu.ActionMenuItem`. `ActionMenuItem` is a subclass of [Component](creating_template_components) and so the rendering of the menu item can be customised through `template_name`, `get_context_data`, `render_html` and `Media`. In addition, the following attributes and methods are available to be overridden:
|
|
|
+Add an item to the popup menu of actions on the page creation and edit views. The callable passed to this hook must return an instance of `wagtail.admin.action_menu.ActionMenuItem`. `ActionMenuItem` is a subclass of [Component](creating_template_components) and so the rendering of the menu item can be customized through `template_name`, `get_context_data`, `render_html`, and `Media`. In addition, the following attributes and methods are available to be overridden:
|
|
|
|
|
|
-- `order` - an integer (default 100) which determines the item's position in the menu. Can also be passed as a keyword argument to the object constructor. The lowest-numbered item in this sequence will be selected as the default menu item; as standard, this is "Save draft" (which has an `order` of 0).
|
|
|
+- `order` - an integer (default 100) that determines the item's position in the menu. Can also be passed as a keyword argument to the object constructor. The lowest-numbered item in this sequence will be selected as the default menu item; as standard, this is "Save draft" (which has an `order` of 0).
|
|
|
- `label` - the displayed text of the menu item
|
|
|
-- `get_url` - a method which returns a URL for the menu item to link to; by default, returns `None` which causes the menu item to behave as a form submit button instead
|
|
|
+- `get_url` - a method that returns a URL for the menu item to link to; by default, returns `None` which causes the menu item to behave as a form submit button instead
|
|
|
- `name` - value of the `name` attribute of the submit button, if no URL is specified
|
|
|
- `icon_name` - icon to display against the menu item
|
|
|
- `classname` - a `class` attribute value to add to the button element
|
|
|
-- `is_shown` - a method which returns a boolean indicating whether the menu item should be shown; by default, true except when editing a locked page
|
|
|
+- `is_shown` - a method that returns a boolean indicating whether the menu item should be shown; by default, true except when editing a locked page
|
|
|
|
|
|
-The `get_url`, `is_shown`, `get_context_data` and `render_html` methods all accept a context dictionary containing the following fields:
|
|
|
+The `get_url`, `is_shown`, `get_context_data`, and `render_html` methods all accept a context dictionary containing the following fields:
|
|
|
|
|
|
- `view` - name of the current view: `'create'`, `'edit'` or `'revisions_revert'`
|
|
|
- `page` - for `view` = `'edit'` or `'revisions_revert'`, the page being edited
|
|
@@ -808,7 +808,7 @@ def remove_submit_to_moderator_option(menu_items, request, context):
|
|
|
menu_items[:] = [item for item in menu_items if item.name != 'action-submit']
|
|
|
```
|
|
|
|
|
|
-The `construct_page_action_menu` hook is called after the menu items have been sorted by their order attributes, and so setting a menu item's order will have no effect at this point. Instead, items can be reordered by changing their position in the list, with the first item being selected as the default action. For example, to change the default action to Publish:
|
|
|
+The `construct_page_action_menu` hook is called after the menu items have been sorted by their order attributes, so setting a menu item's order will have no effect at this point. Instead, items can be reordered by changing their position in the list, with the first item being selected as the default action. For example, to change the default action to Publish:
|
|
|
|
|
|
```python
|
|
|
@hooks.register('construct_page_action_menu')
|
|
@@ -842,7 +842,7 @@ def add_puppy_link_item(request, items):
|
|
|
|
|
|
## Admin workflow
|
|
|
|
|
|
-Hooks for customising the way admins are directed through the process of editing users.
|
|
|
+Hooks for customizing the way admins are directed through the process of editing users.
|
|
|
|
|
|
(after_create_user)=
|
|
|
|
|
@@ -889,7 +889,7 @@ def do_before_create_user(request):
|
|
|
|
|
|
### `after_delete_user`
|
|
|
|
|
|
-Do something after a `User` object is deleted. Uses the same behaviour as `after_create_user`.
|
|
|
+Do something after a `User` object is deleted. Uses the same behavior as `after_create_user`.
|
|
|
|
|
|
(before_delete_user)=
|
|
|
|
|
@@ -897,13 +897,13 @@ Do something after a `User` object is deleted. Uses the same behaviour as `after
|
|
|
|
|
|
Called at the beginning of the "delete user" view passing in the request and the user object.
|
|
|
|
|
|
-Uses the same behaviour as `before_create_user`.
|
|
|
+Uses the same behavior as `before_create_user`.
|
|
|
|
|
|
(after_edit_user)=
|
|
|
|
|
|
### `after_edit_user`
|
|
|
|
|
|
-Do something with a `User` object after it has been updated. Uses the same behaviour as `after_create_user`.
|
|
|
+Do something with a `User` object after it has been updated. Uses the same behavior as `after_create_user`.
|
|
|
|
|
|
(before_edit_user)=
|
|
|
|
|
@@ -911,7 +911,7 @@ Do something with a `User` object after it has been updated. Uses the same behav
|
|
|
|
|
|
Called at the beginning of the "edit user" view passing in the request and the user object.
|
|
|
|
|
|
-Uses the same behaviour as `before_create_user`.
|
|
|
+Uses the same behavior as `before_create_user`.
|
|
|
|
|
|
## Choosers
|
|
|
|
|
@@ -919,7 +919,7 @@ Uses the same behaviour as `before_create_user`.
|
|
|
|
|
|
### `construct_page_chooser_queryset`
|
|
|
|
|
|
-Called when rendering the page chooser view, to allow the page listing QuerySet to be customised. The callable passed into the hook will receive the current page QuerySet and the request object, and must return a Page QuerySet (either the original one, or a new one).
|
|
|
+Called when rendering the page chooser view, to allow the page listing QuerySet to be customized. The callable passed into the hook will receive the current page QuerySet and the request object, and must return a Page QuerySet (either the original one or a new one).
|
|
|
|
|
|
```python
|
|
|
from wagtail import hooks
|
|
@@ -936,7 +936,7 @@ def show_my_pages_only(pages, request):
|
|
|
|
|
|
### `construct_document_chooser_queryset`
|
|
|
|
|
|
-Called when rendering the document chooser view, to allow the document listing QuerySet to be customised. The callable passed into the hook will receive the current document QuerySet and the request object, and must return a Document QuerySet (either the original one, or a new one).
|
|
|
+Called when rendering the document chooser view, to allow the document listing QuerySet to be customized. The callable passed into the hook will receive the current document QuerySet and the request object, and must return a Document QuerySet (either the original one or a new one).
|
|
|
|
|
|
```python
|
|
|
from wagtail import hooks
|
|
@@ -953,7 +953,7 @@ def show_my_uploaded_documents_only(documents, request):
|
|
|
|
|
|
### `construct_image_chooser_queryset`
|
|
|
|
|
|
-Called when rendering the image chooser view, to allow the image listing QuerySet to be customised. The callable passed into the hook will receive the current image QuerySet and the request object, and must return an Image QuerySet (either the original one, or a new one).
|
|
|
+Called when rendering the image chooser view, to allow the image listing QuerySet to be customized. The callable passed into the hook will receive the current image QuerySet and the request object, and must return an Image QuerySet (either the original one or a new one).
|
|
|
|
|
|
```python
|
|
|
from wagtail import hooks
|
|
@@ -972,7 +972,7 @@ def show_my_uploaded_images_only(images, request):
|
|
|
|
|
|
### `construct_explorer_page_queryset`
|
|
|
|
|
|
-Called when rendering the page explorer view, to allow the page listing QuerySet to be customised. The callable passed into the hook will receive the parent page object, the current page QuerySet, and the request object, and must return a Page QuerySet (either the original one, or a new one).
|
|
|
+Called when rendering the page explorer view, to allow the page listing QuerySet to be customized. The callable passed into the hook will receive the parent page object, the current page QuerySet, and the request object, and must return a Page QuerySet (either the original one or a new one).
|
|
|
|
|
|
```python
|
|
|
from wagtail import hooks
|
|
@@ -1010,7 +1010,7 @@ The arguments passed to the hook are as follows:
|
|
|
|
|
|
- `page` - the page object to generate the button for
|
|
|
- `user` - the logged-in user
|
|
|
-- `next_url` - the URL that the linked action should redirect back to on completion of the action, if the view supports it
|
|
|
+- `next_url` - the URL that the linked action should redirect back to on completion of the action if the view supports it
|
|
|
|
|
|
The `priority` argument controls the order the buttons are displayed in. Buttons are ordered from low to high priority, so a button with `priority=10` will be displayed before a button with `priority=20`.
|
|
|
|
|
@@ -1038,7 +1038,7 @@ The arguments passed to the hook are as follows:
|
|
|
|
|
|
- `page` - the page object to generate the button for
|
|
|
- `user` - the logged-in user
|
|
|
-- `next_url` - the URL that the linked action should redirect back to on completion of the action, if the view supports it
|
|
|
+- `next_url` - the URL that the linked action should redirect back to on completion of the action if the view supports it
|
|
|
|
|
|
The `priority` argument controls the order the buttons are displayed in the dropdown. Buttons are ordered from low to high priority, so a button with `priority=10` will be displayed before a button with `priority=60`.
|
|
|
|
|
@@ -1046,7 +1046,7 @@ The `priority` argument controls the order the buttons are displayed in the drop
|
|
|
|
|
|
The admin widgets also provide `ButtonWithDropdownFromHook`, which allows you to define a custom hook for generating a dropdown menu that gets attached to your button.
|
|
|
|
|
|
-Creating a button with a dropdown menu involves two steps. Firstly, you add your button to the `register_page_listing_buttons` hook, just like the example above.
|
|
|
+Creating a button with a dropdown menu involves two steps. Firstly, you add your button to the `register_page_listing_buttons` hook, just like in the example above.
|
|
|
Secondly, you register a new hook that yields the contents of the dropdown menu.
|
|
|
|
|
|
This example shows how Wagtail's default admin dropdown is implemented. You can also see how to register buttons conditionally, in this case by testing the user's permission with `page.permissions_for_user`:
|
|
@@ -1076,7 +1076,7 @@ def page_custom_listing_more_buttons(page, user, next_url=None):
|
|
|
yield wagtailadmin_widgets.Button('Unpublish', reverse('wagtailadmin_pages:unpublish', args=[page.id]), priority=40)
|
|
|
```
|
|
|
|
|
|
-The template for the dropdown button can be customised by overriding `wagtailadmin/pages/listing/_button_with_dropdown.html`. Make sure to leave the dropdown UI component itself as-is.
|
|
|
+The template for the dropdown button can be customized by overriding `wagtailadmin/pages/listing/_button_with_dropdown.html`. Make sure to leave the dropdown UI component itself as-is.
|
|
|
|
|
|
(construct_page_listing_buttons)=
|
|
|
|
|
@@ -1203,7 +1203,7 @@ def before_snippet_delete(request, instances):
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
for instance in instances:
|
|
|
- # Override the deletion behaviour
|
|
|
+ # Override the deletion behavior
|
|
|
instance.delete()
|
|
|
|
|
|
return HttpResponse(f"{total} snippets have been deleted", content_type="text/plain")
|
|
@@ -1214,17 +1214,19 @@ def before_snippet_delete(request, instances):
|
|
|
### `register_snippet_action_menu_item`
|
|
|
|
|
|
Add an item to the popup menu of actions on the snippet creation and edit views.
|
|
|
-The callable passed to this hook receives the snippet's model class as an argument, and must return an instance of `wagtail.snippets.action_menu.ActionMenuItem`. `ActionMenuItem` is a subclass of [Component](creating_template_components) and so the rendering of the menu item can be customised through `template_name`, `get_context_data`, `render_html` and `Media`. In addition, the following attributes and methods are available to be overridden:
|
|
|
+
|
|
|
+The callable passed to this hook receives the snippet's model class as an argument, and must return an instance of `wagtail.snippets.action_menu.
|
|
|
+ActionMenuItem`. `ActionMenuItem` is a subclass of [Component](creating_template_components) and so the rendering of the menu item can be customized through `template_name`, `get_context_data`, `render_html` and `Media`. In addition, the following attributes and methods are available to be overridden:
|
|
|
|
|
|
- `order` - an integer (default 100) which determines the item's position in the menu. Can also be passed as a keyword argument to the object constructor. The lowest-numbered item in this sequence will be selected as the default menu item; as standard, this is "Save draft" (which has an `order` of 0).
|
|
|
- `label` - the displayed text of the menu item
|
|
|
-- `get_url` - a method which returns a URL for the menu item to link to; by default, returns `None` which causes the menu item to behave as a form submit button instead
|
|
|
+- `get_url` - a method that returns a URL for the menu item to link to; by default, returns `None` which causes the menu item to behave as a form submit button instead
|
|
|
- `name` - value of the `name` attribute of the submit button if no URL is specified
|
|
|
- `icon_name` - icon to display against the menu item
|
|
|
- `classname` - a `class` attribute value to add to the button element
|
|
|
-- `is_shown` - a method which returns a boolean indicating whether the menu item should be shown; by default, true except when editing a locked page
|
|
|
+- `is_shown` - a method that returns a boolean indicating whether the menu item should be shown; by default, true except when editing a locked page
|
|
|
|
|
|
-The `get_url`, `is_shown`, `get_context_data` and `render_html` methods all accept a context dictionary containing the following fields:
|
|
|
+The `get_url`, `is_shown`, `get_context_data`, and `render_html` methods all accept a context dictionary containing the following fields:
|
|
|
|
|
|
- `view` - name of the current view: `'create'` or `'edit'`
|
|
|
- `model` - the snippet's model class
|
|
@@ -1253,7 +1255,7 @@ def register_guacamole_menu_item(model):
|
|
|
### `construct_snippet_action_menu`
|
|
|
|
|
|
Modify the final list of action menu items on the snippet creation and edit views.
|
|
|
-The callable passed to this hook receives a list of `ActionMenuItem` objects, a request object and a context dictionary as per `register_snippet_action_menu_item`, and should modify the list of menu items in-place.
|
|
|
+The callable passed to this hook receives a list of `ActionMenuItem` objects, a request object, and a context dictionary as per `register_snippet_action_menu_item`, and should modify the list of menu items in-place.
|
|
|
|
|
|
```python
|
|
|
@hooks.register('construct_snippet_action_menu')
|
|
@@ -1261,7 +1263,7 @@ def remove_delete_option(menu_items, request, context):
|
|
|
menu_items[:] = [item for item in menu_items if item.name != 'delete']
|
|
|
```
|
|
|
|
|
|
-The `construct_snippet_action_menu` hook is called after the menu items have been sorted by their order attributes, and so setting a menu item's order will have no effect at this point. Instead, items can be reordered by changing their position in the list, with the first item being selected as the default action. For example, to change the default action to Delete:
|
|
|
+The `construct_snippet_action_menu` hook is called after the menu items have been sorted by their order attributes, so setting a menu item's order will have no effect at this point. Instead, items can be reordered by changing their position in the list, with the first item being selected as the default action. For example, to change the default action to Delete:
|
|
|
|
|
|
```python
|
|
|
@hooks.register('construct_snippet_action_menu')
|
|
@@ -1298,7 +1300,7 @@ The arguments passed to the hook are as follows:
|
|
|
|
|
|
- `snippet` - the snippet object to generate the button for
|
|
|
- `user` - the user who is viewing the snippets listing
|
|
|
-- `next_url` - the URL that the linked action should redirect back to on completion of the action, if the view supports it
|
|
|
+- `next_url` - the URL that the linked action should redirect back to on completion of the action if the view supports it
|
|
|
|
|
|
The `priority` argument controls the order the buttons are displayed in. Buttons are ordered from low to high priority, so a button with `priority=10` will be displayed before a button with `priority=20`.
|
|
|
|
|
@@ -1316,7 +1318,7 @@ def remove_snippet_listing_button_item(buttons, snippet, user):
|
|
|
|
|
|
## Bulk actions
|
|
|
|
|
|
-Hooks for registering and customising bulk actions. See [](custom_bulk_actions) on how to write custom bulk actions.
|
|
|
+Hooks for registering and customizing bulk actions. See [](custom_bulk_actions) on how to write custom bulk actions.
|
|
|
|
|
|
(register_bulk_action)=
|
|
|
|