Unfortunately there's no examples of admin menu with submenu in Wagtail 6 docs, but here's Nigel van Keulen's solution from Wagtail's Slack #support channel:
# wagtail_hooks.py
from wagtail import hooks
from wagtail.admin.menu import Menu, SubmenuMenuItem, MenuItem, SubMenuItemComponent
from wagtail.images.wagtail_hooks import register_images_menu_item
from wagtail.documents.wagtail_hooks import register_documents_menu_item
from wagtail.admin.wagtail_hooks import register_collections_menu_item
# change app to your main app folder with settings/base.py
from app.settings.base import HIDDEN_SETTINGS_MENU_ITEMS, HIDDEN_MAIN_MENU_ITEMS
assets_menu = Menu(
register_hook_name="register_assets_menu",
construct_hook_name="construct_assets_menu",
)
@hooks.register("register_assets_menu")
def register_assets_menu():
return register_images_menu_item()
@hooks.register("register_assets_menu")
def register_assets_menu_item():
return register_documents_menu_item()
@hooks.register("register_assets_menu")
def register_assets_menu_item():
return register_collections_menu_item()
@hooks.register("register_admin_menu_item")
def register_assets_menu_item():
return SubmenuMenuItem(
_("Assets"),
name="assets",
icon_name="folder-open-1",
menu=assets_menu,
order=300,
)
@hooks.register("construct_settings_menu")
def hide_settings_items(request, menu_items):
menu_items[:] = filter(lambda item: item.name not in HIDDEN_SETTINGS_MENU_ITEMS, menu_items)
@hooks.register("construct_main_menu")
def hide_main_items(request, menu_items):
menu_items[:] = filter(lambda item: item.name not in HIDDEN_MAIN_MENU_ITEMS, menu_items)
# settings/base.py, adjust to needs
HIDDEN_SETTINGS_MENU_ITEMS = [
"collections",
"workflow-tasks",
"workflows",
"redirects",
"menu",
"groups",
"users",
]
HIDDEN_MAIN_MENU_ITEMS = [
"reports",
"images",
"documents",
"wagtaildocs",
"help",
"snippets",
]
Top comments (0)