Skip to content

Commit 9cc4ec8

Browse files
mnoconadriendupuis
andcommitted
Extended the examples to showcase translations for custom page blocks… (#2933)
* Extended the examples to showcase translations for custom page blocks and form fields * Update docs/content_management/pages/create_custom_page_block.md Co-authored-by: Adrien Dupuis <[email protected]> --------- Co-authored-by: Adrien Dupuis <[email protected]>
1 parent 0e215b1 commit 9cc4ec8

File tree

7 files changed

+61
-19
lines changed

7 files changed

+61
-19
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
ibexa_form_builder:
22
fields:
33
country:
4-
name: Country
5-
category: Custom form fields
4+
name: country_field.name
5+
category: custom_category.name
66
thumbnail: '/bundles/ibexaadminuiassets/vendors/ids-assets/dist/img/all-icons.svg#pins-locations'
77
attributes:
88
label:
9-
name: Display label
9+
name: country_field.label.name
1010
type: string
1111
validators:
1212
not_blank:
1313
message: You must provide a label for the field
1414
help:
15-
name: Help text
15+
name: country_field.help.name
1616
type: string
1717
validators:
1818
required: ~

code_samples/page/custom_page_block/config/packages/page_blocks.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
ibexa_fieldtype_page:
22
blocks:
33
event:
4-
name: Event Block
5-
category: Custom
4+
name: event_block.name
5+
category: custom_category.name
66
thumbnail: /bundles/ibexaadminuiassets/vendors/ids-assets/dist/img/all-icons.svg#calendar
77
configuration_template: '@ibexadesign/blocks/event/config.html.twig'
88
views:
99
default:
1010
template: '@ibexadesign/blocks/event/template.html.twig'
11-
name: Default view
11+
name: event_block.view.default
1212
priority: -255
1313
featured:
1414
template: '@ibexadesign/blocks/event/featured_template.html.twig'
15-
name: Featured view
15+
name: event_block.view.featured
1616
priority: 50
1717
attributes:
1818
name:
1919
type: text
20-
name: Event name
20+
name: event_block.name.name
2121
validators:
2222
not_blank:
23-
message: Please provide a name
23+
message: validators.message.event_block.name.validator.not_blank
2424
category:
2525
type: select
26-
name: Select a category
26+
name: event_block.category.name
2727
value: visual
2828
options:
2929
multiple: true
@@ -33,18 +33,18 @@ ibexa_fieldtype_page:
3333
'Sports': sports
3434
event:
3535
type: embed
36-
name: Event
36+
name: event_block.event.name
3737
options:
3838
udw_config_name: block_event_embed
3939
validators:
4040
not_blank:
41-
message: Please select an event
41+
message: validators.message.event_block.embed.validator.not_blank
4242
content_type:
43-
message: Please select an event
43+
message: validators.message.event_block.embed.validator.content_type
4444
options:
4545
types: ['event']
4646
regexp:
47-
message: Choose a content item
47+
message: validators.message.event_block.embed.validator.content_item
4848
options:
4949
pattern: '/[0-9]+/'
5050

docs/content_management/forms/create_custom_form_field.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ For example, to create a Country Form field in the "Custom form fields" category
1616
[[= include_file('code_samples/forms/custom_form_field/config/packages/form_builder.yaml') =]]
1717
```
1818

19+
and provide the translations for the labels in `translations/ibexa_form_builder.en.yaml`:
20+
21+
``` yaml
22+
country_field.name: Country
23+
custom_category.name: Custom form fields
24+
25+
country_field.label.name: Display label
26+
country_field.help.name: Help text
27+
```
28+
1929
Available attribute types are:
2030
2131
|Type|Description|

docs/content_management/pages/create_custom_page_block.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,38 @@ First, add the following [YAML configuration](configuration.md#configuration-fil
2121
[[= include_file('code_samples/page/custom_page_block/config/packages/page_blocks.yaml', 0, 6) =]][[= include_file('code_samples/page/custom_page_block/config/packages/page_blocks.yaml', 16, 49) =]]
2222
```
2323

24+
And provide the translations for the labels:
25+
26+
- in `translations/ibexa_page_builder_block_config.en.yaml`:
27+
28+
``` yaml
29+
event_block.view.default: Default
30+
event_block.view.featured: Featured
31+
32+
event_block.name.name: Name
33+
event_block.category.name: Category
34+
event_block.event.name: Event
35+
```
36+
37+
- in `translations/ibexa_page_fieldtype.en.yaml`:
38+
39+
``` yaml
40+
custom_category.name: Custom category
41+
event_block.name: Event
42+
```
43+
44+
- in `translations/validators.en.yaml`:
45+
46+
``` yaml
47+
validators.message.event_block.name.validator.not_blank: Event name should not be blank.
48+
validators.message.event_block.embed.validator.not_blank: Event content should not be blank.
49+
validators.message.event_block.embed.validator.content_type: Event content should be of type "event".
50+
validators.message.event_block.embed.validator.content_item: Event content should have a numerical ID.
51+
```
52+
2453
`event` is the internal name for the block, and `name` indicates the name under which the block is available in the interface.
2554
You also set up the category in the **Page blocks** toolbox that the block appears in.
26-
In this case, it doesn't show up with the rest of the built-in blocks, but in a separate "Custom" category.
55+
In this case, it doesn't show up with the rest of the built-in blocks, but in a separate "Custom category" category.
2756
The thumbnail for the block can be one of the pre-existing icons, like in the example above, or you can use a custom SVG file.
2857

2958
A block can have multiple attributes that you edit when adding it to a page.

docs/content_management/pages/page_block_attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Each block can have the following properties:
1414
| Attribute | Description |
1515
|--------------|--------------------------------------------------------------------------------------------------------------|
1616
| `type` | Attribute type. |
17-
| `name` | (Optional) The displayed name for the attribute. You can omit it, block identifier is then used as the name. |
17+
| `name` | (Optional) The displayed name for the attribute. You can omit it, block identifier is then used as the name. Translatable using the `ibexa_page_builder_block_config` translation domain. |
1818
| `value` | (Optional) The default value for the attribute. |
1919
| `category` | (Optional) The tab where the attribute is displayed in the block edit modal. |
2020
| `validators` | (Optional) [Validators](page_block_validators.md) checking the attribute value. |

docs/content_management/pages/page_blocks.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Each configured block has an identifier and the following settings:
2020

2121
| Setting | Description |
2222
|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
23-
| `name` | Name of the block used in the Page Builder interface. |
24-
| `category` | Category in the Page Builder **Page blocks** toolbox that the block is shown in. |
23+
| `name` | Name of the block used in the Page Builder interface. Translatable using the `ibexa_page_fieldtype` translation domain. |
24+
| `category` | Category in the Page Builder **Page blocks** toolbox that the block is shown in. Translatable using the `ibexa_page_fieldtype` translation domain. |
2525
| `thumbnail` | Thumbnail used in the Page Builder **Page blocks** toolbox. |
2626
| `views` | Available [templates for the block](#block-templates). |
2727
| `visible` | (Optional) Toggles the block's visibility in the Page Builder **Page blocks** toolbox. Remove the block from the layout before you publish another version of the page. |
@@ -51,6 +51,7 @@ You can overwrite the following properties in the existing blocks:
5151

5252
Page blocks can have multiple templates.
5353
This allows you to create different styles for each block and let the editor choose them when adding the block from the UI.
54+
They names are translatable using the `ibexa_page_builder_block_config` translation domain.
5455

5556
``` yaml
5657
[[= include_file('code_samples/page/custom_page_block/config/packages/page_blocks.yaml', 0, 3) =]][[= include_file('code_samples/page/custom_page_block/config/packages/page_blocks.yaml', 7, 16) =]]

docs/tutorials/page_and_form_tutorial/4_create_a_custom_block.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,5 @@ The Tip of the Day block displays a random Tip from the "Tips" folder.
6767
Refresh the page a few more times and you can see the tip change randomly.
6868

6969
![Random Block with a Tip](enterprise_tut_random_block.png "Random Block with a Tip")
70+
71+
To learn more about custom Page Builder blocks, see [Create custom page block](create_custom_page_block.md).

0 commit comments

Comments
 (0)