Skip to content

Commit

Permalink
Add language links to three dots menu in header
Browse files Browse the repository at this point in the history
  • Loading branch information
wpears committed Dec 20, 2024
1 parent c6de8b9 commit 0409d0e
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions cfgov/v1/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from django.utils.html import format_html_join

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

Expand Down Expand Up @@ -48,33 +47,18 @@
languages = dict(settings.LANGUAGES)


class LanguageMenuItem(ActionMenuItem):
icon_name = "globe"

def __init__(self, label, url):
self.label = label
self.url = url

def get_url(self, context):
return self.url


@hooks.register("construct_page_action_menu")
def add_language_links(menu_items, request, context):
try:
page = context["page"]
return menu_items.extend(
[
LanguageMenuItem(
f"Edit {languages[translation.language]} page",
f"/admin/pages/{translation.pk}/edit/",
)
for translation in page.get_translations()
if translation.language != page.language
]
@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",
)
except KeyError:
pass
for translation in page.get_translations()
if translation.language != page.language
]


@hooks.register("after_delete_page")
Expand Down

0 comments on commit 0409d0e

Please sign in to comment.