Skip to content

IBX-7565: Custom block's UDW config (3.3) #2351

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

Merged
merged 2 commits into from
Apr 4, 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
Expand Up @@ -20,7 +20,7 @@ ezplatform_page_fieldtype:
name: Event name
validators:
not_blank:
message: Please provide a name
message: Please provide a name
category:
type: select
name: Select a category
Expand All @@ -37,3 +37,20 @@ ezplatform_page_fieldtype:
validators:
not_blank:
message: Please select an event
content_type:
message: Please select an event
options:
types: ['event']
regexp:
message: Choose a content item
options:
pattern: '/[0-9]+/'

ezplatform:
system:
default:
universal_discovery_widget_module:
configuration:
block_event_embed:
multiple: false
allowed_content_types: ['event']
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{% extends '@EzPlatformPageBuilder/page_builder/block/config.html.twig' %}

{% block content %}
{% set form_templates = [_self] %}
{{ parent() }}
{% endblock %}

{% block basic_tab_content %}
<div class="ez-block-config__fields">
{{ form_row(form.name) }}
Expand All @@ -15,4 +20,16 @@
</ol>
{% endif %}
</div>
{% endblock %}
{% endblock %}

{% block block_configuration_attribute_embed_widget %}
{% set attr = attr|merge({'hidden': true}) %}
{{ form_widget(form, {'attr': attr})}}
<div class="ez-block-embed-field">
{% include '@EzPlatformPageBuilder/page_builder/block/config/embed_button.html.twig' with {
udw_config_name: 'block_event_embed',
data_open_udw: 'data-open-udw-embed'
} %}
{% include '@EzPlatformPageBuilder/page_builder/block/config/embed_preview.html.twig' %}
</div>
{% endblock %}
23 changes: 18 additions & 5 deletions docs/guide/page/create_custom_page_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The following example shows how to create a block that showcases an event.
First, add the following YAML configuration:

``` yaml
[[= 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, 39) =]]
[[= 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, 47) =]]
```

`event` is the internal name for the block, and `name` indicates the name under which the block is available in the interface.
Expand All @@ -31,7 +31,10 @@ and an event Content item that you select and embed.

For a list of all available attribute types, see [Page block attributes](page_block_attributes.md).

Each attribute can have [validators](page_block_validators.md). The `not_blank` validators in the example ensure that the user fills in the two block fields.
Each attribute can have [validators](page_block_validators.md).
The `not_blank` validators in the example ensure that the user fills in the two block fields.
The `content_type` validator in the example ensure that the user choose a content item of the content type `event`.
The `regexp` validator ensure that the final value looks like a content ID.

## Add block templates

Expand All @@ -56,7 +59,7 @@ The templates have access to all block attributes, as you can see above in the `
Priority of templates indicates the order in which they are presented in Page Builder.
The template with the greatest priority is used as the default one.

## Add edit templates
## Add edit template

You can also customize the template for the block settings modal.
Do this under the `configuration_template` key:
Expand All @@ -65,11 +68,21 @@ Do this under the `configuration_template` key:
[[= include_file('code_samples/page/custom_page_block/config/packages/page_blocks.yaml', 0, 7) =]]
```

Place the edit template in `templates/themes/<your_theme>/blocks/event/config.html.twig'`:
Place the edit template in `templates/themes/<your_theme>/blocks/event/config.html.twig`:

``` html+twig
[[= include_file('code_samples/page/custom_page_block/templates/themes/standard/blocks/event/config.html.twig') =]]
```

This example template overrides the `embed` attribute widget to customize the Universal Discovery Widget (UDW).
It adds itself to the `form_templates` and defines a `block_configuration_attribute_embed_widget` block.
The following UDW configuration is used so only an `event` typed content item can be selected:

``` yaml
[[= include_file('code_samples/page/custom_page_block/config/packages/page_blocks.yaml', 48, 57) =]]
```

For more information, see [UDW configuration](extending_udw.md#udw-configuration).

Your custom page block is now ready.
Before you can use it in Page Builder, you must [enable it in Page field settings]([[= user_doc =]]/content_management/configure_ct_field_settings/#block-display).
Before you can use it in Page Builder, you must [enable it in Page field settings]([[= user_doc =]]/content_management/configure_ct_field_settings/#block-display).
4 changes: 4 additions & 0 deletions docs/guide/page/page_block_attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ attributes:
third_field: integer
```

`embed` and `locationlist` use the Universal Discovery Widget (UDW).
When creating a block with these two types you can configure the UDW behavior.
For more information, see [Create custom page block / Add edit template](create_custom_page_block.md#add-edit-template)

## Custom attribute types

You can create custom attribute type to add to Page blocks.
Expand Down