1from wagtail.core import blocks
2
3
4class LinkBlock(blocks.StructBlock):
5    title = blocks.CharBlock()
6    url = blocks.URLBlock()
7
8    def get_context(self, value, parent_context=None):
9        context = super().get_context(value, parent_context)
10        context['classname'] = parent_context['classname'] if value['title'] == 'Torchbox' else 'normal'
11        return context
12
13    def get_form_context(self, value, prefix='', errors=None):
14        context = super().get_form_context(value, prefix=prefix, errors=errors)
15        context['extra_var'] = "Hello from get_form_context!"
16        return context
17
18    class Meta:
19        icon = "site"
20        template = 'tests/blocks/link_block.html'
21        form_template = 'tests/block_forms/link_block.html'
22
23
24class SectionBlock(blocks.StructBlock):
25    title = blocks.CharBlock()
26    body = blocks.RichTextBlock()
27
28    class Meta:
29        icon = "form"
30        template = 'tests/blocks/section_block.html'
31