Skip to content

Commit eebc28b

Browse files
authored
Merge pull request #240 from magento-devdocs/develop
[Owls] Docs Update for How-to Topics
2 parents c303a47 + c77e6fe commit eebc28b

11 files changed

+289
-313
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Use this access to:
99

1010
Should you find an issue in Page Builder functionality, please report it on GitHub.
1111

12+
## Documentation
13+
14+
Please use this link to access the latest Page Builder documentation: https://devdocs.magento.com/page-builder/docs/index.html
15+
1216
## GitHub installation only
1317

1418
**The pre-release version of Page Builder MUST be installed by cloning the GitHub repos as described here.**
@@ -43,11 +47,6 @@ Before installing Page Builder, make sure you have:
4347
bin/magento setup:upgrade
4448
```
4549

46-
## Developer documentation
47-
48-
We will update the developer documentation frequently during beta. Please use this link to access the latest updates: 
49-
[Page Builder developer documentation](https://devdocs.magedevteam.com/72/page-builder/docs/getting-started/introduction.html)
50-
5150
## Contribute to Page Builder
5251

5352
We appreciate any and all contributions to Page Builder. If you are interested in contributing to this repository, please see our [Contribution Guide].

docs/configurations/storefront-configuration.md

Lines changed: 0 additions & 72 deletions
This file was deleted.

docs/getting-started/introduction.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ See [Install Page Builder](install-pagebuilder.md)
4444
* [Block chooser configuration](../configurations/block-chooser-configuration.md)
4545
* [Full-width page layout configuration](../configurations/full-width-page-layout-configuration.md)
4646
* [Responsive layout configuration](../configurations/responsive-layout-configuration.md)
47-
* [Storefront configuration](../configurations/storefront-configuration.md)
4847
* [Selector configuration](../configurations/selector-configuration.md)
4948
* [Product conditions configuration](../configurations/product-conditions-configuration.md)
5049
* [Server-side rendered previews](../configurations/server-side-rendered-previews.md)
@@ -53,15 +52,15 @@ See [Install Page Builder](install-pagebuilder.md)
5352

5453
* [How to develop a container content type](../how-to/how-to-develop-container-content-type.md)
5554
* [How to use the Image Uploader](../how-to/how-to-use-image-uploader.md)
56-
* [How to use the Image Uploader](../how-to/how-to-use-image-uploader.md)
5755
* [How to add inline text editing](../how-to/how-to-add-inline-text-editing.md)
5856
* [How to add a custom toolbar](../how-to/how-to-add-custom-toolbar.md)
57+
* [How to add a storefront widget](../how-to/how-to-add-storefront-widget.md)
5958
* [How to convert product attribute fields to use Page Builder](../how-to/how-to-convert-product-attributes-to-use-pagebuilder.md)
60-
* [How to store a component master format as a widget-directive](../how-to/how-to-store-master-format-as-widget-directive.md)
6159

6260
### Reference
6361

6462
* [Architecture](../reference/architecture.md)
63+
* [Datastore](../reference/data-store.md)
6564
* [Events](../reference/events.md)
6665
* [Knockout bindings](../reference/knockout-bindings.md)
6766

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# How to add a storefront widget
2+
3+
A storefront widget is a JavaScript component that handles the behavior of a content type after Page Builder renders it on the storefront.
4+
For example, the Tabs and Sliders have their own storefront widgets to handle the end-user's tapping of tabs and swiping of slides on the storefront.
5+
However, Page Builder also executes storefront widgets on the Admin stage for block and dynamic block content types.
6+
This allows end-users to preview how Page Builder will render the blocks and dynamic blocks on the storefront.
7+
8+
Adding a storefront widget to your content type is a simple two-step process:
9+
10+
![How to add storefront widget](../images/how-to-add-storefront-widget.svg)
11+
12+
## Step 1: Create the JavaScript
13+
14+
Name your JavaScript file `widget.js` and put it in the following directory structure: `/view/base/web/js/content-type/{content-type-name}/appearance/{appearance-name}/widget.js`. An example from the PageBuilderQuote content type follows:
15+
16+
![Where to add storefront widget](../images/where-to-add-widget.png){:width="477px" height="auto"}
17+
18+
The JavaScript for the widget can handle events, initialize third-party controls, or do whatever else you need to control your content type's behavior _after_ Page Builder renders the master format template on the frontend (or within a block or dynamic block on the Admin stage).
19+
20+
``` javascript
21+
define([
22+
'jquery',
23+
], function ($) {
24+
'use strict';
25+
26+
return function (config, element) {
27+
var element = $(element);
28+
console.log("ELEMENT: " + element.data('element'));
29+
};
30+
});
31+
```
32+
33+
## Step 2: Configure the widget initializer
34+
35+
To configure your `widget.js` so that Page Builder can initialize and load it, create a new `WidgetInitializerConfig` type in your module's global `di.xml` file (`etc/di.xml`). Then add your custom configuration (that includes your widget) as a replacement argument. The following example is from the PageBuilderQuote module:
36+
37+
``` xml
38+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
39+
<type name="Magento\PageBuilder\Model\WidgetInitializerConfig">
40+
<arguments>
41+
<argument name="config" xsi:type="array">
42+
<item name="example_quote" xsi:type="array">
43+
<!-- Name is the appearance name -->
44+
<item name="default" xsi:type="array">
45+
<!--required argument-->
46+
<item name="component" xsi:type="string">Example_PageBuilderQuote/js/content-type/example-quote/appearance/default/widget</item>
47+
</item>
48+
</item>
49+
</argument>
50+
</arguments>
51+
</type>
52+
</config>
53+
```
54+
55+
That's it! For more examples, look at several of Page Builder's native widget implementations within `app/code/Magento/PageBuilder/view/base/web/js/content-type/`.
Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
# How to use the Image Uploader
1+
# How to add an image uploader
22

3-
## What's in this topic
3+
This topic describes how to add the image uploader component to your content type so that end-users can add images from the Admin stage as needed.
44

5-
This topic describes how to add a reusable image uploader component to the PageBuilder stage for a content type.
5+
![How to add an image uploader](../images/how-to-add-image-uploader.svg)
66

7-
## Overview
7+
## Step 1: Add configuration data for the uploader
88

9-
To add image uploader customization to PageBuilder:
10-
- [Add configuration for the uploader](#add-configuration-for-the-uploader)
11-
- [Update the `<YourModule>/view/adminhtml/web/js/content-type/<content_type_name>/preview.js` file {#js-file}](#js-file)
12-
- [Update the preview template to display the uploader component {#preview}](#preview)
13-
14-
## Add configuration for the uploader {#add-configuration-for-the-uploader}
15-
16-
Use `additional_data` in your `<YourModule>/view/base/pagebuilder/content_type/<content-type-name>.xml` XML config file to add the image uploader custom configuration to a content type:
9+
The first step is to customize the image uploader to suit your needs. To do this, you must add the `additional_data` element to your content type's config file to create the data types and values needed to initialize the image uploader for your specific needs.
1710

1811
``` xml
12+
<?xml version="1.0"?>
1913
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_PageBuilder:etc/content_type.xsd">
20-
<type name="MyName" translate="label" label="MyName" icon="icon-modulename-simple" component="Vendor_ModuleName/js/content-type" form="modulename_simple_form" menu_section="layout">
21-
...
14+
<type name="example_quote"
15+
...
2216
<additional_data>
2317
<item name="uploaderConfig" xsi:type="array">
2418
<item name="isShowImageUploadInstructions" xsi:type="boolean">false</item>
@@ -49,64 +43,46 @@ Use `additional_data` in your `<YourModule>/view/base/pagebuilder/content_type/<
4943
</config>
5044
```
5145

52-
## Update the `<YourModule>/view/adminhtml/web/js/content-type/<content_type_name>/preview.js` file {#js-file}
53-
54-
To update the `<YourModule>/view/adminhtml/web/js/content-type/<content_type_name>/preview.js` file:
55-
56-
1. Import the 'Magento_PageBuilder/js/content-type/uploader' component as a dependency:
57-
58-
``` js
59-
define(['Magento_PageBuilder/js/content-type/uploader'], function (Uploader) {
60-
```
61-
62-
**Constructor arguments**
63-
64-
| Argument | Type | Description | Required | Default |
65-
| ------------------ | --------- | ----------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------- |
66-
| `name` | String | Used to locate the component in the UI registry once it is created. | yes | None |
67-
| `uploaderConfig` | Object | Initializes the image uploader UI component. | yes | None |
68-
| `contentTypeId` | String | The ID of the parent content type this will be used in. | yes | None |
69-
| `dataStore` | DataStore | The DataStore that the selected image should be stored in. | yes | None |
70-
| `initialValue` | Object[] | The value to be used for the initial state of the component. | yes | None |
71-
| `onChangeCallback` | Function | A callback that will be called when an image is selected. | no | The image will be saved to the provided `dataStore` using `uploaderConfig.dataScope` as the key. |
72-
| `onDeleteCallback` | Function | A callback that will be called when the current used image is deleted from storage. | no | The image will be removed from to the provided `dataStore` using `uploaderConfig.dataScope` as the key. |
46+
## Step 2: Create an instance of the uploader
7347

74-
The following is an example extracted from the image content type:
48+
To create an instance of the image uploader in your preview component (`preview.js`), import the `Magento_PageBuilder/js/content-type/uploader` component as a dependency and call the uploader constructor, passing in your content type's configuration options (added in step 1) and the other required arguments, as shown here :
7549

76-
```js
77-
var dataStore = this.parent.dataStore.getState();
78-
var initialImageValue = dataStore[this.config.additional_data.uploaderConfig.dataScope] || "";
79-
80-
this.uploader = new Uploader(
81-
'imageuploader_' + this.parent.id,
82-
this.config.additional_data.uploaderConfig,
83-
this.parent.id,
84-
this.parent.dataStore,
85-
initialImageValue,
86-
);
87-
```
50+
``` js
51+
define(['Magento_PageBuilder/js/content-type/uploader'], function (Uploader) {
52+
53+
Preview.prototype.getUploader = function () {
54+
var initialImageValue = this.contentType.dataStore
55+
.get(this.config.additional_data.uploaderConfig.dataScope, "");
56+
57+
return new Uploader(
58+
"imageuploader_" + this.contentType.id,
59+
this.config.additional_data.uploaderConfig,
60+
this.contentType.id,
61+
this.contentType.dataStore,
62+
initialImageValue,
63+
);
64+
};
65+
```
8866
89-
2. Add configuration for the uploader in the `<content-type-name>.xml` file to initialize the uploader.
67+
**Uploader constructor arguments**
9068
91-
3. Register the listener to specify when the image is loaded from the uploader UI component:
9269
93-
``` js
94-
/**
95-
* Get registry callback reference to uploader UI component
96-
*
97-
* @returns {Uploader}
98-
*/
99-
public getUploader() {
100-
return this.uploader;
101-
}
102-
```
70+
| Argument | Type | Description | Required | Default |
71+
| ------------------ | --------- | ----------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------- |
72+
| `name` | String | Used to locate the component in the UI registry. | yes | None |
73+
| `uploaderConfig` | Object | Initializes the image uploader UI component with the configuration settings from the `additional_data` element. | yes | None |
74+
| `contentTypeId` | String | The ID of the content type you are adding the uploader to. | yes | None |
75+
| `dataStore` | DataStore | The DataStore to store the selected image in. | yes | None |
76+
| `initialValue` | Object[] | The image value to set for the initial state of the uploader component. | yes | None |
77+
| `onChangeCallback` | Function | The callback to execute when the end-user selects an image. | no | Magento saves the image to the provided `dataStore` using `uploaderConfig.dataScope` as the key. |
78+
| `onDeleteCallback` | Function | The callback to execute when the end-user deletes the current image from storage. | no | Magento removes the image from to the provided `dataStore` using `uploaderConfig.dataScope` as the key. |
10379
104-
## Update the preview template to display the uploader component {#preview}
80+
## Step 3: Add markup for the uploader
10581
106-
Update the preview template file, `bluefoot/app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/<content-type-name>/<ppearance_name>/preview.html`, to display the uploader component:
82+
To add the image uploader to your preview template (`preview.html`), use Knockout's `scope` binding element to render an instance of your configured uploader component from the Magento registry, as shown here:
10783
10884
``` html
109-
<div>
85+
<div ...>
11086
...
11187
<scope args="getUploader().getUiComponent()">
11288
<render />
@@ -115,4 +91,5 @@ Update the preview template file, `bluefoot/app/code/Magento/PageBuilder/view/ad
11591
</div>
11692
```
11793
118-
**Note:** When a file is deleted from the media browser, the `fileDeleted` event is triggered on the window with the `mediabrowser` namespace. The passed argument is an object containing the `ids` property, which is an array of ID strings for each of the deleted files. The IDs of the selected files are provided in the objects dispatched by the `addFile` and `processFile` methods inside the image uploader UI Component.
94+
{: .bs-callout .bs-callout-info }
95+
When an end-user deletes a file from the media browser, Magento triggers the `fileDeleted` event on the window with the `mediabrowser` namespace. The passed argument is an object containing the `ids` property, which is an array of ID strings for each of the deleted files. Magento adds the IDs of the selected files in the objects dispatched by the `addFile` and `processFile` methods inside the image uploader component.

0 commit comments

Comments
 (0)