Skip to content

Commit c1d7b8e

Browse files
committed
MC-5769: Complete content type tutorial
Updated, added content for first three tutorial topics
1 parent 65017b0 commit c1d7b8e

10 files changed

+166
-52
lines changed

docs/create-basic-content-type/overview.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,52 @@ The development of this tutorial is currently **IN PROGRESS**.
55

66
***
77

8-
Page Builder comes with 16 content types (controls) you can use to build your storefront pages. In this tutorial, you will add a new content type: a Quote control, which you can use to show customer testimonials or other quotations on a page.
8+
Page Builder comes with 16 content types (controls) you can use to build your storefront pages. In this tutorial, you will add a new content type: a **Quote** control, which you can use to show customer testimonials or other quotations within your storefront.
99

1010
![Page Builder Content Types](../images/panel-horizontal.png)
1111

12+
## Quote content type
13+
14+
Our Quote control will look like this when rendered in the Admin UI within a three-column grid:
15+
16+
![QuoteTypeDisplay](../images/QuoteTypeDisplay.png)
17+
18+
And it will look like this when it's shown on a page in the storefront:
19+
20+
![StorefrontTestimonials](../images/StorefrontTestimonials.png)
21+
22+
23+
1224
## Prerequisites
1325

14-
Page Builder creates content types from a module with UI components. This tutorial assumes you have a basic module structure (as follows) in which to add your content type files.
26+
This tutorial assumes you are starting with a basic, registered module, as follows.
1527

1628
![Minimum module structure](../images/module-minimum-structure.png)
1729

30+
31+
1832
## Overview
1933

34+
The steps for building the Quote content type are illustrated and described below. While the reality is not quite this linear, these steps do represent the basic phases and flow for building new Page Builder content types.
35+
2036
![Creating Custom Content Types](../images/content-type-overview.png)
2137

22-
1. **Add configuration**: Create an XML file to define your content type and reference the other files that control the appearances and behaviors of your content type.
38+
1. **Add configuration**: Create an XML file to define your content type and reference the other files that control the appearance and behavior of your content type.
2339
2. **Add templates**: Create HTML templates that define the appearance of your content types on the Admin stage (preview.html) and the storefront (master.html).
2440
3. **Add component**: Create a JavaScript file that defines the behavior of your content type on the Admin stage (preview.js) and the storefront (master.js).
2541
4. **Add form**: Create a UI component form and a layout so users can edit your content type within the Page Builder editor.
2642
5. **Add styles**: Create LESS files to style your content types when rendered in the Admin UI and on the storefront.
2743
6. **Add frontend widget**: Create a JavaScript file to control the UI behavior (user interactivity) of your content type on the storefront.
2844

29-
## Content type files
45+
## File structure
3046

31-
The files you will need to create in order to build a basic content type are shown here.
47+
Before you get started, take a look at what you will be building. The block on the left shows the empty module structure you will start with. The block on the right shows all the files you will add to your module, labeled by the steps in the process.
3248

3349
![Before and after content type](../images/content-type-files.png)
3450

51+
## Conventions
52+
53+
The file structure represents an overview of the conventions used for content types. Many of the conventions used are simply those defined for developing UI components. However, the conventions specific to Page Builder start within the directories called `content_type` or `content-type`. Page Builder instantiates a content type from the files defined within these directories. We discuss these conventions within each step of the process.
54+
3555
## Next
3656
[Step 1: Add configuration](step-1-add-configuration.md).

docs/create-basic-content-type/step-1-add-configuration.md

Lines changed: 98 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,87 @@ The development of this tutorial is currently **IN PROGRESS**.
55

66
***
77

8-
The configuration file gives your content type its existence. It's where you set the name, display label, and references to the other files that define the appearance and behavior of your content type. Add it to your module here (`view/adminhtml/pagebuilder/content_type/`):
8+
The configuration file defines the basic settings and files that compose your content type.
9+
10+
## Convention
11+
12+
By convention, Page Builder requires the configuration for a content type to be in the `adminhtml` area within a directory named `pagebuilder` and a subdirectory named `content_type` or `content-type`.
13+
14+
The name of your configuration file should also reflect the name of your content type. Our example content type is called Quote, so we should name our configuration file `quote.xml` and add it to our module within the following directory structure (`view/adminhtml/pagebuilder/content_type/`):
915

1016
![Create config file](../images/step1-add-config-file.png)
1117

12-
The file name should reflect the name of your content type. Use underscores to separate multi-word names as needed.
18+
{: .bs-callout .bs-callout-info }
19+
If your content type name uses multiple words, use underscores to separate the words in the name.
1320

1421
## Example configuration
1522

1623
{: .bs-callout .bs-callout-info }
17-
Only a subset of configuration elements are described in this example (enough to understand the configuration file's role within a content type). For more details, refer to [Main configurations](../configurations/content-type-configuration.md) and [Additional configurations](../configurations/additional-configurations.md).
24+
In this example, only a subset of configuration elements are described (enough to understand the configuration file's basic role). For more details, refer to [Content type configurations](../configurations/content-type-configuration.md) and [Additional configurations](../configurations/additional-configurations.md).
1825

1926

20-
The following configuration shows the minimal requirements for defining a content type called `example`. The `example` content type is nearly identical to the built-in `heading` content type in order to help you learn the fundamental parts of a content type as seen in the configuration file here. An overview of these elements and attributes are described in the tables that follow.
27+
The following configuration shows the complete configuration file for our Quote content type. An overview of these elements and attributes are described in the tables that follow.
2128

2229
```xml
2330
<?xml version="1.0"?>
2431
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_PageBuilder:etc/content_type.xsd">
25-
<type name="example"
26-
label="Example"
32+
<type name="quote"
33+
label="Quote"
2734
group="elements"
2835
component="Magento_PageBuilder/js/content-type"
29-
preview_component="Vendor_Module/js/content-type/example/preview"
36+
preview_component="Magento_PageBuilder/js/content-type/preview"
3037
master_component="Magento_PageBuilder/js/content-type/master"
31-
form="pagebuilder_example_form"
38+
form="pagebuilder_quote_form"
3239
icon="icon-pagebuilder-heading"
3340
sortOrder="21"
3441
translate="label">
3542
<children default_policy="deny"/>
43+
<parents default_policy="deny">
44+
<parent name="column" policy="allow"/>
45+
</parents>
3646
<appearances>
3747
<appearance name="default"
3848
default="true"
39-
preview_template="Vendor_Module/content-type/example/default/preview"
40-
render_template="Vendor_Module/content-type/example/default/master"
49+
preview_template="Vendor_Module/content-type/quote/default/preview"
50+
render_template="Vendor_Module/content-type/quote/default/master"
4151
reader="Magento_PageBuilder/js/master-format/read/configurable">
4252
<elements>
4353
<element name="main">
4454
<style name="text_align" source="text_align"/>
4555
<style name="border" source="border_style" converter="Magento_PageBuilder/js/converter/style/border-style"/>
4656
<style name="border_color" source="border_color"/>
57+
<style name="background_color" source="background_color"/>
4758
<style name="border_width" source="border_width" converter="Magento_PageBuilder/js/converter/style/border-width"/>
4859
<style name="border_radius" source="border_radius" converter="Magento_PageBuilder/js/converter/style/remove-px"/>
49-
<style name="display" source="display" converter="Magento_PageBuilder/js/converter/style/display" preview_converter="Magento_PageBuilder/js/converter/style/preview/display"/>
5060
<style name="margins" storage_key="margins_and_padding" reader="Magento_PageBuilder/js/property/margins" converter="Magento_PageBuilder/js/converter/style/margins"/>
5161
<style name="padding" storage_key="margins_and_padding" reader="Magento_PageBuilder/js/property/paddings" converter="Magento_PageBuilder/js/converter/style/paddings"/>
62+
<style name="display" source="display" converter="Magento_PageBuilder/js/converter/style/display" preview_converter="Magento_PageBuilder/js/converter/style/preview/display"/>
5263
<attribute name="name" source="data-role"/>
5364
<attribute name="appearance" source="data-appearance"/>
54-
<html name="example_text" converter="Magento_PageBuilder/js/converter/html/tag-escaper"/>
5565
<css name="css_classes"/>
5666
</element>
67+
<element name="quote">
68+
<html name="quote_text" converter="Magento_PageBuilder/js/converter/html/tag-escaper"/>
69+
<css name="quote_css"/>
70+
</element>
71+
<element name="author">
72+
<style name="text_align" source="text_align"/>
73+
<html name="quote_author" converter="Magento_PageBuilder/js/converter/html/tag-escaper"/>
74+
</element>
75+
<element name="author_title">
76+
<style name="text_align" source="text_align"/>
77+
<html name="quote_author_desc" converter="Magento_PageBuilder/js/converter/html/tag-escaper"/>
78+
</element>
5779
</elements>
5880
</appearance>
5981
</appearances>
6082
</type>
6183
</config>
6284
```
6385

64-
## The `type` node
86+
## The `type` element
6587

66-
The `<type>` node defines the key properties of your content type. The attributes are described here:
88+
The `<type>` element defines the key properties of your content type. The attributes are described here:
6789

6890
| Attribute | Description |
6991
|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -78,26 +100,75 @@ The `<type>` node defines the key properties of your content type. The attribute
78100
| `sortOrder` | Optional. The listed order within the menu group. For example, `sortOrder=21` puts the content type third in the `Elements` menu group, after the content types with `sortOrder`s of 10 and 20. |
79101
| `translate` | Identifies the attribute you want Magento to translate. Here, the `label` value is set for translation. |
80102

81-
## The `appearance` node
103+
## The `children` element
104+
105+
The `children` element determines if your content type can contain other content types as children. In the Admin UI, it either allows or prevents you from dragging and dropping *other* content types from the panel into *your* content type.
106+
107+
```xml
108+
<children default_policy="deny"/>
109+
```
110+
111+
In our configuration, we don't allow any other content types to be children of our content type. Put another way, our content type cannot be a parent; we only want it to be the child of other content types, which leads us to the `parents` element.
112+
113+
## The `parents` element
82114

83-
The purpose of the `<appearance>` node in a configuration is to define how your content type appears when it is dragged on the stage in the in the Admin UI (using the`preview.html` template) and when it's displayed in the storefront for customers (using the `master.html` template).
115+
The `parents` element determines if other content types can be a parent to your content type. In the Admin UI, it either allows or prevents you from dragging and dropping *your* content type into *other* content types on the stage.
116+
117+
```xml
118+
<parents default_policy="deny">
119+
<parent name="column" policy="allow"/>
120+
</parents>
121+
```
122+
123+
In our configuration, the `parents` element first prevents our content type from having any parents. If we left it there, we could not drag our content type onto the stage at all because even the stage is a parent. So we limit our content type's parents to only one: the `column` content type. This allows you to drag and drop your content type into columns, but nowhere else.
124+
125+
## The `appearances` element
126+
127+
The `<appearances>` element specifies one or more views for displaying your content type. For example, the Banner has four appearances you can choose from within its editor as shown here:
128+
129+
![BannerTemplateAppearanceExample](../images/BannerTemplateAppearanceExample.png)
130+
131+
Each of these appearances are defined as an `appearance` within the Banner configuration file (`app/code/Magento/PageBuilder/view/adminhtml/pagebuilder/content_type/banner.xml`):
132+
133+
```xml
134+
<appearances>
135+
<appearance name="collage-left"...>
136+
<appearance name="collage-centered"...>
137+
<appearance name="collage-right"...>
138+
<appearance name="poster" default="true" ...>
139+
</appearances>
140+
```
141+
142+
Going further, each `appearance` is defined by exactly two HTML templates, one to display a preview appearance in the Admin (`preview.html`) and the other to display the master appearance (`master.html`) on your storefront. We will discuss HTML templates more in [Step 2: Add templates](step-2-add-templates.md).
143+
144+
Our Quote only has one appearance, so we define it as the default:
145+
146+
```xml
147+
<appearances>
148+
<appearance name="default"
149+
default="true"
150+
preview_template="Vendor_Module/content-type/quote/default/preview"
151+
render_template="Vendor_Module/content-type/quote/default/master"
152+
reader="Magento_PageBuilder/js/master-format/read/configurable">
153+
<elements...>
154+
</appearance>
155+
</appearances>
156+
```
84157

85158
The `<appearance>` attributes are described as follows:
86159

87-
| Attribute | Description |
88-
|--------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
89-
| `name` | Name of the appearance for extending as needed. |
160+
| Attribute | Description |
161+
| ------------------ | ------------------------------------------------------------ |
162+
| `name` | Name of the appearance so it can be extended as needed. |
90163
| `default` | Content types must specify one of the appearances as the default appearance. That means if you only have one appearance, it must be set as the default. |
91-
| `preview_template` | `preview.html` - the HTML template for rendering the preview appearance of a content type within the Admin. |
92-
| `render_template` | `master.html` - the HTML template for rendering the storefront appearance of a content type for customers. |
93-
| `reader` | Reads data for the content type from the master format |
94-
95-
All content types must have at least one `<appearance>` defined within the `<appearances>` node.
164+
| `preview_template` | `preview.html` - the HTML template for rendering the preview appearance of a content type on the Admin stage during page development. |
165+
| `render_template` | `master.html` - the HTML template for rendering the storefront appearance of a content type for customers. |
166+
| `reader` | Reads data for the content type from the master format |
96167

97-
## The `elements` node
168+
## The `elements` element
98169

99-
The purpose of `<elements>` node in the configuration is to map the data from the form to the content type's master format so that the values entered in the editor can be stored and rendered correctly within both the Admin preview and the storefront. These nodes will be explained more fully in Step 4: Add editor.
170+
The purpose of `<elements>` as defined within an appearance is to map the data from the content type's edit form to the content type's master format so that the values entered in the form can be stored and rendered correctly on the Admin stage and storefront. These elements will be explained more fully in [Step 4: Add form](step-4-add-form.md)
100171

101172
## Next
102173

103-
At this point, if you try to view Page Builder you get an error noting that the `preview_template` and `render_template` from the `<appearance>` element are missing. These templates are referenced in the `example.xml` config file, but we have not yet created them. Let's do that next in [Step 2: Add templates](step-2-add-templates.md).
174+
[Step 2: Add templates](step-2-add-templates.md).

0 commit comments

Comments
 (0)