Skip to content

Commit

Permalink
Merge pull request #8606 from cfpb/language-in-action-menu
Browse files Browse the repository at this point in the history
Add wagtail hook to create menu items for translations
  • Loading branch information
higs4281 authored Dec 27, 2024
2 parents fce1436 + cda6ec6 commit b072389
Showing 1 changed file with 17 additions and 1 deletion.
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

0 comments on commit b072389

Please sign in to comment.