Skip to content

Commit afc8cd0

Browse files
committed
MC-6270: Add docs for content type component
Updating from PR review
1 parent badb5e3 commit afc8cd0

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

docs/create-basic-content-type/step-3-add-components.md

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

66
***
77

8-
In this step, we will create a preview component in order to show you how to customize the Quote options menu.
8+
In this step, we will create a preview component in order to customize the options menu for our Quote. The options menu is the popup menu that appears when you mouseover a content type, as shown here:
9+
10+
![Create config file](../images/options-menu-default.png)
11+
12+
The options menu provides end-users with several functions, including a button to open the content type's form editor, which we will add in [Step 4: Add form](step-4-add-form.md).
913

1014
## About components
1115

12-
Components are the JavaScript files that define the behaviors of your content type when they appear on the stage in the Admin UI (using the `preview.js` component) and in the storefront (using the `master.js` component). As such, they are complementary to the templates you added previously in Step 2, acting as the view models to the template's views.
16+
Components are JavaScript files that define the behaviors of your content type when they appear on the Admin stage (using the `preview.js` component) and in the storefront (using the `master.js` component). As such, they are complementary to the templates you added previously in Step 2, acting as the view models to the template's views.
1317

14-
Custom component files are completely optional. If they are not added to your content type, Page Builder will use these defaults:
18+
Adding custom component files to your content types is completely optional. Whether you need one or not will depend on the complexity of your content type. If you do not add components to your content type, Page Builder will use these defaults:
1519

1620
- Default preview component: `Magento_PageBuilder/js/content-type/preview`
1721
- Default master component: `Magento_PageBuilder/js/content-type/master`
1822

19-
Reasons for adding your own preview component include customizing options menus and adding user-interactivity that your content type needs to fulfill its function when displayed on the Admin stage. Adding your own master component is necessary if you want to... **[Reviewer: please give some examples of when custom master components might be necessary.]**
23+
When you start developing more complex content types, you will need to create custom preview components in order to make these and other functions available on the Admin stage:
24+
25+
- Initiating and using additional 3rd party libraries like sliders and tabs.
26+
- Adding image uploader support.
27+
- Providing dynamic data into your preview templates from the back-end.
28+
- Allowing the back-end to conduct rendering (such as our block and dynamic block content types).
29+
- Declaring special states based on the data stored, for example, showing a disabled state when certain fields are set to specific values.
30+
31+
Examples of implementing these functions will be add to future tutorials and other topics in this documentation.
32+
33+
Adding your own master component is far less common. The master component is only necessary if you want to manipulate the final output of your content type before it is persisted to the database.
2034

2135
## Component conventions
2236

2337
The conventions for naming your components and adding them to your module are as follows:
2438

2539
- Your preview component must be named `preview.js` and placed here in your module (`view/adminhtml/web/js/content-type/example-quote/`):
2640

27-
![Create config file](../images/step3-add-component.png)
41+
![Create config file](../images/step3-add-component.png)
2842

2943
- Your master component must be named `master.js` and placed here in your module (`view/frontend/web/js/content-type/example-quote/`):
3044

3145
![Create config file](../images/step3-add-master-component.png)
3246

3347
We will not create a master component for our Quote example, but the location is given here if you need to include one for more complex content types.
3448

35-
Before continuing, add the preview component file (``preview.js`) to your `PageBuilderQuote` module within the directory structure noted.
49+
Before continuing, add the preview component file (`preview.js`) to your `PageBuilderQuote` module within the directory structure noted.
3650

3751
## Component configuration
3852

@@ -55,7 +69,7 @@ A description of each component-related attribute from the Quote configuration f
5569

5670
| Attribute | Description |
5771
| ------------------- | ------------------------------------------------------------ |
58-
| `component` | There are two component types to choose from: `content-type` and `content-type-collection`. Use `Magento_PageBuilder/js/content-type` for static content types that do not have children (like our Quote). Use `Magento_PageBuilder/js/content-type-collection` for content types that can contain children (container content types). |
72+
| `component` | Page Builder provides two component types to choose from: `content-type` and `content-type-collection`. Use `Magento_PageBuilder/js/content-type` for static content types that do not have children (like our Quote). Use `Magento_PageBuilder/js/content-type-collection` for content types that can contain children (container content types). You can also create and specify your own component implementations, provided they conform to the Page Builder interfaces. |
5973
| `preview_component` | Optional. The `preview.js` file provides rendering logic to the Admin preview template. If your content type does not require any changes to Page Builder's standard rendering logic, you can omit this attribute from the the `type` element. When you omit the attribute, Page Builder will use `Magento_PageBuilder/js/content-type/preview` by default.<br /><br />However, if you want to make changes to the option menu for your content type, or other customize other user-interactivity in the Admin, you need to create your own preview component as we have done for the Quote content type. |
6074
| `master_component` | Optional. The `master.js` file provides rendering logic to the master format storefront template. As with the `preview_component`, if your content type does not require any specific user-interactivity or other behavior when it's displayed in the storefront, you can simply omit this attribute from the the `type` element. When you omit the attribute, Page Builder will use `Magento_PageBuilder/js/content-type/master` by default. <br /><br />In the Quote configuration, the `master_component` attribute is only included for discussion. It simply points to the Page Builder default `master.js` component that would be used the attribute was omitted. |
6175

@@ -79,10 +93,6 @@ define([
7993

8094
Preview.prototype.retrieveOptions = function retrieveOptions() {
8195
var options = $super.retrieveOptions.call(this, arguments);
82-
//console.log(options);
83-
84-
// Change option menu title
85-
options.title.preview.config.label = "Quote Menu";
8696

8797
// Change option menu icons
8898
options.remove.icon = "<i class='icon-admin-pagebuilder-error'></i>";
@@ -137,10 +147,6 @@ To do this, we need to override the protected `retrieveOptions()` function from
137147
```js
138148
Preview.prototype.retrieveOptions = function retrieveOptions() {
139149
var options = $super.retrieveOptions.call(this, arguments);
140-
//console.log(options);
141-
142-
// Change option menu title
143-
options.title.preview.config.label = "Quote Menu";
144150

145151
// Change option menu icons
146152
options.remove.icon = "<i class='icon-admin-pagebuilder-error'></i>";
@@ -161,26 +167,17 @@ Preview.prototype.retrieveOptions = function retrieveOptions() {
161167
};
162168
```
163169
164-
In the preceding code, we made changes to the options menu title, icons, and tooltips. You can also remove options from the menu. For example, if you don't want end-users to move or duplicate your content type, you can remove those options from your menu using `delete options.move` and `delete options.duplicate` as shown commented out in the code.
170+
In the preceding code, we made changes to the options menu icons and tooltips. You can also remove options from the menu. For example, if you don't want end-users to move or duplicate your content type, you can remove those options from your menu using `delete options.move` and `delete options.duplicate` as shown commented out in the code.
165171
166172
![Create config file](../images/options-menu-custom.png)
167173
168174
{: .bs-callout .bs-callout-info }
169175
Even though you can change the base option menu properties as described, we suggest you stick the the default options as much as possible to provide end-users with a consistent experience across Magento's content types and other third-party content types that are included as time goes on.
170176
171-
### Other changes
172-
173-
Other changes and additions you can make to your preview component include:
174-
175-
**[Reviewer: Please include a list of other changes or additions that developers might make in their own preview component]**
176-
177-
178-
179177
## Quote `master_component`
180178
181-
As mentioned previously, our Quote content type has no need for a master.js component file. Instead, we are using Page Builder's default master component file: `Magento_PageBuilder/js/content-type/master`. More information on master components and their usage can be found **[where?]**
179+
As mentioned previously, our Quote content type has no need for a master component. We are using Page Builder's default master component file: `Magento_PageBuilder/js/content-type/master`.
182180
183181
## Next
184182
185183
[Step 4: Add form](step-4-add-form.md)
186-

0 commit comments

Comments
 (0)