Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wagtail hook to create menu items for translations #8606

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion cfgov/v1/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.utils.html import format_html_join

from wagtail import hooks
from wagtail.admin import messages
from wagtail.admin import messages, widgets
from wagtail.admin.menu import MenuItem
from wagtail.snippets.models import register_snippet

Expand Down Expand Up @@ -44,6 +44,22 @@

logger = logging.getLogger(__name__)

languages = dict(settings.LANGUAGES)


@hooks.register("register_page_header_buttons")
def page_header_buttons(page, user, view_name, next_url=None):
return [
widgets.Button(
f"Edit {languages[translation.language]} page",
f"/admin/pages/{translation.pk}/edit/",
priority=1000,
icon_name="globe",
)
for translation in page.get_translations()
if translation.language != page.language
]


@hooks.register("after_delete_page")
def log_page_deletion(request, page):
Expand Down
Loading