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

Fix blog newsletter signup id on translated pages #12917

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from wagtail import blocks
from wagtail.models import Locale
from wagtail.snippets.blocks import SnippetChooserBlock


Expand All @@ -13,6 +14,18 @@ class Meta:
class BlogNewsletterSignupBlock(blocks.StructBlock):
signup = SnippetChooserBlock("wagtailpages.BlogSignup")

def get_context(self, value, parent_context=None):
context = super().get_context(value, parent_context)

signup = value.get("signup")

if signup:
# Get the default locale signup and pass the signup id back to the context
unlocalized_signup = signup.get_translation_or_none(Locale.get_default()) or signup
context["unlocalized_signupid"] = unlocalized_signup.id

return context

class Meta:
icon = "placeholder"
template = "wagtailpages/blocks/blog_newsletter_signup_block.html"
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
data-module-type="default"
data-form-style="blog-body"
data-form-position="blog-body"
data-signup-id="{{ self.signup.id | unlocalize }}"
data-signup-id="{{ unlocalized_signupid }}"
data-button-text="{% trans "Sign up" context "Submit button for newsletter signup form" %}"
data-cta-header="{{ self.signup.header | escape }}"
data-cta-description="{{ self.signup.description | escape }}"
Expand Down
Loading