From f8a6e88554c6eb13caba680fc9d794b2b7505493 Mon Sep 17 00:00:00 2001 From: Sharmaine Lim Date: Mon, 3 Feb 2025 15:04:27 +0800 Subject: [PATCH] TWE-16 - BE - Optional intro & button fields for blog/work chooser blocks (#339) * Add intro to BlogChooserBlock * Add intro to WorkChooserBlock * Comment out intro from pattern library for now * Add primary & secondary buttons also, commented out from the YAML file * Add comments we only expect 1 button --- tbx/core/blocks.py | 10 ++++++++++ .../blocks/blog_chooser_block.html | 19 +++++++++++++++++++ .../blocks/blog_chooser_block.yaml | 11 ++++++++++- .../blocks/work_chooser_block.html | 19 +++++++++++++++++++ .../blocks/work_chooser_block.yaml | 9 +++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/tbx/core/blocks.py b/tbx/core/blocks.py index 05e5507bb..582815e54 100644 --- a/tbx/core/blocks.py +++ b/tbx/core/blocks.py @@ -654,11 +654,16 @@ def clean(self, value): class BlogChooserBlock(blocks.StructBlock): featured_blog_heading = blocks.CharBlock(max_length=255) + intro = blocks.RichTextBlock( + features=settings.NO_HEADING_RICH_TEXT_FEATURES, required=False + ) blog_pages = blocks.ListBlock( blocks.PageChooserBlock(page_type="blog.BlogPage"), min_num=1, max_num=3, ) + primary_button = LinkBlock(label="Primary button", required=False) + secondary_button = LinkBlock(label="Secondary button", required=False) def get_context(self, value, parent_context=None): context = super().get_context(value, parent_context=parent_context) @@ -680,11 +685,16 @@ def get_context(self, value, parent_context=None): class WorkChooserBlock(blocks.StructBlock): featured_work_heading = blocks.CharBlock(max_length=255) + intro = blocks.RichTextBlock( + features=settings.NO_HEADING_RICH_TEXT_FEATURES, required=False + ) work_pages = blocks.ListBlock( blocks.PageChooserBlock(page_type=["work.WorkPage", "work.HistoricalWorkPage"]), min_num=1, max_num=3, ) + primary_button = LinkBlock(label="Primary button", required=False) + secondary_button = LinkBlock(label="Secondary button", required=False) def get_context(self, value, parent_context=None): context = super().get_context(value, parent_context) diff --git a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/blog_chooser_block.html b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/blog_chooser_block.html index 075b5d6ae..2e4121238 100644 --- a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/blog_chooser_block.html +++ b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/blog_chooser_block.html @@ -1,11 +1,20 @@ {% load wagtailcore_tags %} +{# Section heading #} {% if is_standard_page %}

{{ value.featured_blog_heading }}

{% else %} {% include "patterns/atoms/motif-heading/motif-heading.html" with heading_level=2 heading=value.featured_blog_heading classes="motif-heading--two motif-heading--static motif-heading--half-width section-title--related-posts" %} {% endif %} +{# Section intro #} +{% if value.intro %} +
+ {{ value.intro|richtext }} +
+{% endif %} + +{# Blog posts #} + +{# We expect only up to 1 primary button (`max_num=1` is set in the block definition.) #} +{% for button in value.primary_button %} + {{ button.value.text }} +{% endfor %} + +{# We expect only up to 1 secondary button (`max_num=1` is set in the block definition.) #} +{% for button in value.secondary_button %} + {{ button.value.text }} +{% endfor %} diff --git a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/blog_chooser_block.yaml b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/blog_chooser_block.yaml index 6c0552cdf..f8535139b 100644 --- a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/blog_chooser_block.yaml +++ b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/blog_chooser_block.yaml @@ -1,6 +1,15 @@ context: value: - featured_blog_heading: Case studies + featured_blog_heading: Blog posts + # intro: '

An injection of fresh ideas, and the occasional challenging opinion, to ignite your fire.

' + # primary_button: + # - value: + # text: Primary button + # url: '#' + # secondary_button: + # - value: + # text: Secondary button + # url: '#' blog_pages: - title: Explore the potential of AI in content management date: 20 Oct 2023 diff --git a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/work_chooser_block.html b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/work_chooser_block.html index 17d962775..bb8cb4d0b 100644 --- a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/work_chooser_block.html +++ b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/work_chooser_block.html @@ -1,12 +1,21 @@ {% load wagtailcore_tags %} {% if work_pages %} + {# Section heading #} {% if is_standard_page %}

{{ value.featured_work_heading }}

{% else %} {% include "patterns/atoms/motif-heading/motif-heading.html" with heading_level=2 heading=value.featured_work_heading classes="motif-heading--two motif-heading--static motif-heading--half-width section-title--related-posts" %} {% endif %} + {# Section intro #} + {% if value.intro %} +
+ {{ value.intro|richtext }} +
+ {% endif %} + + {# Work pages / Case study pages #} {% endif %} + +{# We expect only up to 1 primary button (`max_num=1` is set in the block definition.) #} +{% for button in value.primary_button %} + {{ button.value.text }} +{% endfor %} + +{# We expect only up to 1 secondary button (`max_num=1` is set in the block definition.) #} +{% for button in value.secondary_button %} + {{ button.value.text }} +{% endfor %} diff --git a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/work_chooser_block.yaml b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/work_chooser_block.yaml index 138eca9c5..7aca6b447 100644 --- a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/work_chooser_block.yaml +++ b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/work_chooser_block.yaml @@ -1,6 +1,15 @@ context: value: featured_work_heading: Case studies + # intro: '

An injection of fresh ideas, and the occasional challenging opinion, to ignite your fire.

' + # primary_button: + # - value: + # text: Primary button + # url: '#' + # secondary_button: + # - value: + # text: Secondary button + # url: '#' work_pages: - title: Imagining and designing a future product for MQ in 5 days flat client: 'MQ: Transforming Mental Health'