Skip to content

Commit aa362a4

Browse files
author
Robert He
committed
MAGETWO-90887: Documentation
- added visual-select.md doc file
1 parent f441458 commit aa362a4

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Visual Select
2+
3+
## What's in this topic
4+
This topic describes how to extend some Page Builder fields to accommodate a custom look and feel for the text alignment option.
5+
6+
The text alignment field for each content block, in the Advanced section, now shows an icon and title. You can customize the text alignment field to show this new look and feel for all content blocks.
7+
8+
All image formats are supported for icons, though we suggest using an SVG format.
9+
10+
## Overview
11+
12+
To add Visual Select customization to a Page Builder content block:
13+
1. [Override the select component with an element template](#element-template)
14+
2. [Add Visual Select to the XML config](#xml-config)
15+
16+
## Override the select component with an element template {#element-template}
17+
18+
We use the default select component in the `/app/code/Magento/PageBuilder/view/adminhtml/ui-component/pagebuilder_base_form.xml` file. You can override the default template, specifying an element template for this functionality, to implement the Visual Select option.
19+
20+
In the provided template, specify `<elementTmpl>`:
21+
22+
``` xml
23+
<field name="text_align" sortOrder="10" formElement="select">
24+
<settings>
25+
<dataType>text</dataType>
26+
<label translate="true">Alignment</label>
27+
<elementTmpl>Magento_PageBuilder/form/element/align</elementTmpl>
28+
</settings>
29+
```
30+
31+
## Add Visual Select to the XML config {#xml-config}
32+
33+
The available options for select, `value`, `title`, and `icon`, can be provided by the PHP class that implements the `\Magento\Framework\Option\ArrayInterface` method.
34+
35+
Options should return an array with the following format:
36+
37+
``` php
38+
[
39+
value => "value", //key used in the component dataSource
40+
title => "Title",
41+
icon => "path/to/picture/on/server"
42+
]
43+
```
44+
45+
These new configuration values are used in the `align.html` template file stored in Page Builder's `app/code/Magento/Pagebuilder/view/adminhtml/web/template/form/element` directory.
46+
47+
Use a virtual type of `Magento\PageBuilder\Model\Source\VisualSelect` in your module's `di.xml` configuration file to define the options in a visual select field.
48+
49+
``` xml
50+
<virtualType name="AlignmentSource" type="Magento\PageBuilder\Model\Source\VisualSelect">
51+
<arguments>
52+
<argument name="optionsSize" xsi:type="string">small</argument>
53+
<argument name="optionsData" xsi:type="array">
54+
<item name="0" xsi:type="array">
55+
<item name="value" xsi:type="string">default</item>
56+
<item name="title" xsi:type="string" translate="true">Default</item>
57+
</item>
58+
<item name="1" xsi:type="array">
59+
<item name="value" xsi:type="string">left</item>
60+
<item name="title" xsi:type="string" translate="true">Left</item>
61+
<item name="icon" xsi:type="string">Magento_PageBuilder/css/images/form/element/visual-select/alignment/left.svg</item>
62+
</item>
63+
<item name="2" xsi:type="array">
64+
<item name="value" xsi:type="string">center</item>
65+
<item name="title" xsi:type="string" translate="true">Center</item>
66+
<item name="icon" xsi:type="string">Magento_PageBuilder/css/images/form/element/visual-select/alignment/center.svg</item>
67+
</item>
68+
<item name="3" xsi:type="array">
69+
<item name="value" xsi:type="string">right</item>
70+
<item name="title" xsi:type="string" translate="true">Right</item>
71+
<item name="icon" xsi:type="string">Magento_PageBuilder/css/images/form/element/visual-select/alignment/right.svg</item>
72+
</item>
73+
</argument>
74+
</arguments>
75+
</virtualType>
76+
```

0 commit comments

Comments
 (0)