Skip to content

Commit f1b4040

Browse files
committed
PB-73: Create Appearances example and documentation
Updated after review
1 parent b92b482 commit f1b4040

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

docs/how-to/how-to-add-appearance.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
Appearances provide different layout and styling options for a content type. For example, the Banner content type has four appearances. Each appearance shows a different layout for the Banner's text and button.
44

5-
This topic shows how to add appearances to existing content types. An overview of the steps and the files you need to add are illustrated here:
5+
This topic shows how to add appearances to Page Builder's native content types. An overview of the steps and the files you need to add are illustrated here:
66

77
![How to add an appearance](../images/how-to-add-appearance.svg)
88

99
_Steps for adding appearances_
1010

11-
Even though this topic describes how to add appearances to Page Builder's native content types, the steps can be applied to adding more appearances to your custom content types as well.
11+
These steps also apply to adding appearances to your custom content types and third-party content types.
1212

13-
## Step 1: Add VisualSelect class
13+
## Step 1: Add virtual type for VisualSelect class
1414

1515
First, we need a way select an appearance within the Admin UI. In Page Builder, we use the `VisualSelect` class. This class provides the UI for selecting different appearances. For example, the `VisualSelect` class for the Banner provides four appearances to choose from:
1616

@@ -24,15 +24,14 @@ To add a new appearance option for one of Page Builder's native content types, l
2424

2525
_File and location for the VisualSelect class_
2626

27-
Within the `di.xml` file, add a `VisualSelect` class using the Banner's `VisualSelect` class name (`<virtualType name="AppearanceSourceBanner"`), as shown here:
27+
Within the `di.xml` file, add a virtual type using the`VisualSelect` class with the Banner's virtual type name (`<virtualType name="AppearanceSourceBanner"`), as shown here:
2828

2929
```xml
3030
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3131
<virtualType name="AppearanceSourceBanner" type="Magento\PageBuilder\Model\Source\VisualSelect">
3232
<arguments>
33-
<argument name="optionsSize" xsi:type="string">large</argument>
3433
<argument name="optionsData" xsi:type="array">
35-
<item name="4" xsi:type="array">
34+
<item name="simple-poster" xsi:type="array">
3635
<item name="value" xsi:type="string">simple-poster</item>
3736
<item name="title" xsi:type="string" translate="true">Simple Poster</item>
3837
<item name="icon" xsi:type="string">Example_PageBuilderBannerAppearance/css/images/content-type/banner/appearance/simple-poster.svg</item>
@@ -50,7 +49,6 @@ The following table describes the configuration arguments for each appearance op
5049

5150
| Arguments | Description |
5251
| --------------- | ------------------------------------------------------------ |
53-
| `optionsSize` | The size of the icons that display each option. Use `large` for appearance options. |
5452
| `optionsData` | Grouping array for all the appearance options of a content type. |
5553
| `item array` | Grouping array of properties that define an appearance option. The `name="4"` signifies the index order for displaying the option. The Banner's existing options stop with an index of 3 (`name="3"`), ensuring that our new appearance option is positioned after the last Banner option. |
5654
| `value` | Assigns the unique key used in the component dataSource. |
@@ -59,15 +57,15 @@ The following table describes the configuration arguments for each appearance op
5957
| `noticeMessage` | (Not shown in example.) The `noticeMessage` displays a message below the appearance options when the appearance is selected. For example, two of the Row appearances (`full-width` and `full-bleed`) define `noticeMessage` strings that display when selected. |
6058
{:style="table-layout:auto"}
6159

62-
To add more appearance options, simply create more ` item` arrays, as shown here:
60+
To add more appearance options, simply create more `item` arrays, as shown here:
6361

6462
```xml
65-
<item name="5" xsi:type="array">
63+
<item name="tall" xsi:type="array">
6664
<item name="value" xsi:type="string">tall</item>
6765
<item name="title" xsi:type="string" translate="true">Tall</item>
6866
<item name="icon" xsi:type="string">Example_PageBuilderExtensionBanner/css/images/content-type/banner/appearance/tall.svg</item>
6967
</item>
70-
<item name="6" xsi:type="array">
68+
<item name="short" xsi:type="array">
7169
<item name="value" xsi:type="string">short</item>
7270
<item name="title" xsi:type="string" translate="true">Short</item>
7371
<item name="icon" xsi:type="string">Example_PageBuilderBannerExtensionBanner/css/images/content-type/banner/appearance/short.svg</item>
@@ -167,6 +165,15 @@ _Additional simple-poster appearance for the Banner content type_
167165

168166
Appearances for a content type can share the same form or use different forms. For example, the Products content type uses two different forms, one for each appearance. The Grid appearance uses the `pagebuilder_products_form.xml` to provide options for displaying products in a grid. While the Carousel appearance uses the `pagebuilder_products_carousel_form.xml` to provide extra options for displaying products in a carousel.
169167

168+
When you select an appearance with its own form, Page Builder replaces the content type's form (defined in the `<type>` element) with the appearance's form. But when you select an appearance that does not have a form defined, the appearance switches back to using the content type's form.
169+
170+
```xml
171+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...>
172+
<type name="products"
173+
form="pagebuilder_products_form"
174+
```
175+
_Content type form used by default for all appearances_
176+
170177
To add a form for an appearance, add a `<form>` element as a child of the `<appearance>` element in your content type's config file. As mentioned, the Products content type does this for its Carousel appearance, shown here:
171178

172179
```xml
@@ -182,15 +189,15 @@ _Adding a form to an appearance_
182189

183190
## Step 4: Add appearance templates
184191

185-
Appearances use different HTML templates to create different layouts and apply different styles to those layouts. For example, the Banner content type uses four sets of `preview.html` and `master.html` templates, to create the visual differences for each content type:
192+
Appearances use different HTML templates to create different layouts and apply different styles to those layouts. For example, the Banner content type uses four sets of `preview.html` and `master.html` templates to create the visual differences for each content type:
186193

187194
![Appearance configuration config file](../images/appearance-templates-banner.png)
188195

189196
_Banner appearance templates_
190197

191-
Each template set is located within a folder named after the appearance for which they are used. The folder names must match the appearance names assigned in the content type's config file.
198+
Notice how Page Builder organizes the Banner templates by appearance name. We recommend the same practice when adding templates for your appearances.
192199

193-
To create appearance templates for additional Banner appearances, such as the `simple-poster` appearance described in steps 1 and 2, you must add a new appearance folder for your module's templates, as shown here:
200+
To create appearance templates for additional Banner appearances, such as the `simple-poster` appearance described in steps 1 and 2, add a new appearance folder for your module's templates, as shown here:
194201

195202
![Appearance templates](../images/appearance-templates-additional.png)
196203

0 commit comments

Comments
 (0)