Skip to content

Commit 10bfc3b

Browse files
committed
Merge branch 'MC-1405' of github.com:magento-trigger/magento2-page-builder into MC-1405
2 parents a6913c9 + d0ac333 commit 10bfc3b

26 files changed

+229
-149
lines changed

app/code/Magento/PageBuilder/docs/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
[Render a backend content type preview]: content-type-preview.md
3838
[Custom Toolbar]: toolbar.md
3939
[Full width page layouts]: full-width-page-layouts.md
40-
[Add image uploader to content type]: image-uploader.md
40+
[Add custom logic to content types]: add-custom-logic.md
4141
[Roadmap and Known Issues]: roadmap.md
4242
[How to create custom PageBuilder content type container]: how-to-create-custom-content-type-container.md
4343

app/code/Magento/PageBuilder/docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ It replaces the default WYSIWYG Editor in the Admin area with a highly configura
2929
1. [Render a backend content type preview]
3030
1. [Custom Toolbar]
3131
1. [Full width page layouts]
32+
1. [Add custom logic to content types]
3233
5. [Roadmap and known issues]
3334
6. [How to create custom PageBuilder content type container]
3435

@@ -56,6 +57,6 @@ It replaces the default WYSIWYG Editor in the Admin area with a highly configura
5657
[Render a backend content type preview]: content-type-preview.md
5758
[Custom Toolbar]: toolbar.md
5859
[Full width page layouts]: full-width-page-layouts.md
59-
[Add image uploader to content type]: image-uploader.md
60+
[Add custom logic to content types]: add-custom-logic.md
6061
[Roadmap and Known Issues]: roadmap.md
6162
[How to create custom PageBuilder content type container]: how-to-create-custom-content-type-container.md
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Add custom logic to content types
2+
3+
## Navigation
4+
5+
1. [Introduction]
6+
2. [Installation guide]
7+
3. [Contribution guide]
8+
4. [Developer documentation]
9+
1. [Architecture overview]
10+
1. [BlueFoot to PageBuilder data migration]
11+
1. [Third-party content type migration]
12+
1. [Iconography]
13+
1. [Add image uploader to content type]
14+
1. [Module integration]
15+
1. [Additional data configuration]
16+
1. [Content type configuration]
17+
1. [How to add a new content type]
18+
1. [Events]
19+
1. [Bindings]
20+
1. [Master format]
21+
1. [Visual select]
22+
1. [Reuse product conditions in content types]
23+
1. [Store component master format as widget directive]
24+
1. [Use the block chooser UI component]
25+
1. [Use the inline text editing component]
26+
1. [Render a backend content type preview]
27+
1. [Custom Toolbar]
28+
1. [Full width page layouts]
29+
1. **Add custom logic to content types**
30+
5. [Roadmap and known issues]
31+
6. [How to create custom PageBuilder content type container]
32+
33+
[Introduction]: README.md
34+
[Contribution guide]: CONTRIBUTING.md
35+
[Installation guide]: install.md
36+
[Developer documentation]: developer-documentation.md
37+
[Architecture overview]: architecture-overview.md
38+
[BlueFoot to PageBuilder data migration]: bluefoot-data-migration.md
39+
[Third-party content type migration]: new-content-type-example.md
40+
[Iconography]: iconography.md
41+
[Add image uploader to content type]: image-uploader.md
42+
[Module integration]: module-integration.md
43+
[Additional data configuration]: custom-configuration.md
44+
[Content type configuration]: content-type-configuration.md
45+
[How to add a new content type]: how-to-add-new-content-type.md
46+
[Events]: events.md
47+
[Bindings]: bindings.md
48+
[Master format]: master-format.md
49+
[Visual select]: visual-select.md
50+
[Reuse product conditions in content types]: product-conditions.md
51+
[Store component master format as widget directive]: widget-directive.md
52+
[Use the block chooser UI component]: block-chooser-component.md
53+
[Use the inline text editing component]: inline-editing-component.md
54+
[Render a backend content type preview]: content-type-preview.md
55+
[Custom Toolbar]: toolbar.md
56+
[Full width page layouts]: full-width-page-layouts.md
57+
[Add custom logic to content types]: add-custom-logic.md
58+
[Roadmap and Known Issues]: roadmap.md
59+
[How to create custom PageBuilder content type container]: how-to-create-custom-content-type-container.md
60+
61+
You can customize PageBuilder content types by adding your own logic on the frontend.
62+
63+
To add custom logic to content types:
64+
1. [Create a JavaScript widget](#create-a-javascript-widget).
65+
2. [Add XML configuration to load it on the frontend](#add-xml-configuration-to-load-it-on-the-frontend).
66+
67+
### Create a JavaScript widget
68+
69+
Create a JavaScript widget in your module's `/view/frontend/web/js/content-type/{content-type-name}/appearance/{appearance-name}/widget.js` file:
70+
71+
``` javascript
72+
/**
73+
* Copyright © Magento, Inc. All rights reserved.
74+
* See COPYING.txt for license details.
75+
*/
76+
77+
define([
78+
'jquery',
79+
'slick'
80+
], function ($) {
81+
'use strict';
82+
83+
return function (config, sliderElement) {
84+
85+
var $element = $(sliderElement);
86+
87+
/**
88+
* Prevent each slick slider from being initialized more than once which could throw an error.
89+
*/
90+
if ($element.hasClass('slick-initialized')) {
91+
$element.slick('unslick');
92+
}
93+
94+
$element.slick({
95+
autoplay: $element.data('autoplay') === 1,
96+
autoplaySpeed: $element.data('autoplay-speed') || 0,
97+
fade: $element.data('fade') === 1,
98+
infinite: $element.data('is-infinite') === 1,
99+
arrows: $element.data('show-arrows') === 1,
100+
dots: $element.data('show-dots') === 1
101+
});
102+
};
103+
});
104+
105+
```
106+
107+
### Add XML configuration to load it on the frontend
108+
109+
Add XML configuration to load it on the frontend, and on the stage, so that you can preview content inside both the block and dynamic block content types.
110+
111+
Add the following configuration to the `etc/di.xml` file in your custom module directory:
112+
113+
``` xml
114+
<type name="Magento\PageBuilder\Model\Config\ContentType\WidgetInitializer">
115+
<arguments>
116+
<argument name="config" xsi:type="array">
117+
<item name="%content-type-name%" xsi:type="array">
118+
<!-- Name is the appearance name -->
119+
<item name="default" xsi:type="array">
120+
<!--required argument-->
121+
<item name="component" xsi:type="string">%{vendor-path}/js/content-type/{content-type-name}/appearance/{appearance-name}/widget%</item>
122+
<!--optional if you need provide some config for your widget-->
123+
<item name="config" xsi:type="array">
124+
<item name="buttonSelector" xsi:type="string">.pagebuilder-slide-button</item>
125+
<item name="showOverlay" xsi:type="string">hover</item>
126+
</item>
127+
<!--optional if you want load widget per appearance-->
128+
<item name="appearance" xsi:type="string">default</item>
129+
</item>
130+
</item>
131+
</argument>
132+
</arguments>
133+
</type>
134+
```

app/code/Magento/PageBuilder/docs/architecture-overview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
1. [Render a backend content type preview]
2727
1. [Custom Toolbar]
2828
1. [Full width page layouts]
29+
1. [Add custom logic to content types]
2930
5. [Roadmap and known issues]
3031
6. [How to create custom PageBuilder content type container]
3132

@@ -53,7 +54,7 @@
5354
[Render a backend content type preview]: content-type-preview.md
5455
[Custom Toolbar]: toolbar.md
5556
[Full width page layouts]: full-width-page-layouts.md
56-
[Add image uploader to content type]: image-uploader.md
57+
[Add custom logic to content types]: add-custom-logic.md
5758
[Roadmap and Known Issues]: roadmap.md
5859
[How to create custom PageBuilder content type container]: how-to-create-custom-content-type-container.md
5960

app/code/Magento/PageBuilder/docs/bindings.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
1. [Render a backend content type preview]
2727
1. [Custom Toolbar]
2828
1. [Full width page layouts]
29+
1. [Add custom logic to content types]
2930
5. [Roadmap and known issues]
3031
6. [How to create custom PageBuilder content type container]
3132

@@ -53,7 +54,7 @@
5354
[Render a backend content type preview]: content-type-preview.md
5455
[Custom Toolbar]: toolbar.md
5556
[Full width page layouts]: full-width-page-layouts.md
56-
[Add image uploader to content type]: image-uploader.md
57+
[Add custom logic to content types]: add-custom-logic.md
5758
[Roadmap and Known Issues]: roadmap.md
5859
[How to create custom PageBuilder content type container]: how-to-create-custom-content-type-container.md
5960

app/code/Magento/PageBuilder/docs/block-chooser-component.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
1. [Render a backend content type preview]
2727
1. [Custom Toolbar]
2828
1. [Full width page layouts]
29+
1. [Add custom logic to content types]
2930
5. [Roadmap and known issues]
30-
6. [How to create custom PageBuilder content type container
31+
6. [How to create custom PageBuilder content type container]
3132

3233
[Introduction]: README.md
3334
[Contribution guide]: CONTRIBUTING.md
@@ -53,11 +54,10 @@
5354
[Render a backend content type preview]: content-type-preview.md
5455
[Custom Toolbar]: toolbar.md
5556
[Full width page layouts]: full-width-page-layouts.md
56-
[Add image uploader to content type]: image-uploader.md
57+
[Add custom logic to content types]: add-custom-logic.md
5758
[Roadmap and Known Issues]: roadmap.md
5859
[How to create custom PageBuilder content type container]: how-to-create-custom-content-type-container.md
5960

60-
6161
## What's in this topic
6262

6363
This topic describes how to use the block chooser UI component for a custom content type.

app/code/Magento/PageBuilder/docs/bluefoot-data-migration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
1. [Render a backend content type preview]
2727
1. [Custom Toolbar]
2828
1. [Full width page layouts]
29+
1. [Add custom logic to content types]
2930
5. [Roadmap and known issues]
3031
6. [How to create custom PageBuilder content type container]
3132

@@ -53,7 +54,7 @@
5354
[Render a backend content type preview]: content-type-preview.md
5455
[Custom Toolbar]: toolbar.md
5556
[Full width page layouts]: full-width-page-layouts.md
56-
[Add image uploader to content type]: image-uploader.md
57+
[Add custom logic to content types]: add-custom-logic.md
5758
[Roadmap and Known Issues]: roadmap.md
5859
[How to create custom PageBuilder content type container]: how-to-create-custom-content-type-container.md
5960

app/code/Magento/PageBuilder/docs/content-type-configuration.md

Lines changed: 2 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
1. [Render a backend content type preview]
3030
1. [Custom Toolbar]
3131
1. [Full width page layouts]
32+
1. [Add custom logic to content types]
3233
5. [Roadmap and known issues]
3334
6. [How to create custom PageBuilder content type container]
3435

@@ -56,7 +57,7 @@
5657
[Render a backend content type preview]: content-type-preview.md
5758
[Custom Toolbar]: toolbar.md
5859
[Full width page layouts]: full-width-page-layouts.md
59-
[Add image uploader to content type]: image-uploader.md
60+
[Add custom logic to content types]: add-custom-logic.md
6061
[Roadmap and Known Issues]: roadmap.md
6162
[How to create custom PageBuilder content type container]: how-to-create-custom-content-type-container.md
6263

@@ -546,120 +547,3 @@ define([], function () {
546547
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -------------- |
547548
|`fieldsToIgnoreOnRemove`| array containing field names to ignore when evaluating whether an element has been configured. The default value is an empty array. | `["tab_name"]` |
548549

549-
550-
## Add custom logic to content types
551-
552-
You can customize PageBuilder content types by adding your own logic on the frontend.
553-
554-
To add custom logic to content types:
555-
1. [Create a JavaScript widget](#create-a-javascript-widget).
556-
2. [Add XML configuration to load it on the frontend](#add-xml-configuration-to-load-it-on-the-frontend).
557-
558-
### Create a JavaScript widget
559-
560-
Create a JavaScript widget in your module's `/view/frontend/web/js/content-type/{content-type-name}/appearance/{appearance-name}/widget.js` file:
561-
562-
``` javascript
563-
/**
564-
* Copyright © Magento, Inc. All rights reserved.
565-
* See COPYING.txt for license details.
566-
*/
567-
568-
define([
569-
'jquery',
570-
'slick'
571-
], function ($) {
572-
'use strict';
573-
574-
return function (config, sliderElement) {
575-
576-
var $element = $(sliderElement);
577-
578-
/**
579-
* Prevent each slick slider from being initialized more than once which could throw an error.
580-
*/
581-
if ($element.hasClass('slick-initialized')) {
582-
$element.slick('unslick');
583-
}
584-
585-
$element.slick({
586-
autoplay: $element.data('autoplay') === 1,
587-
autoplaySpeed: $element.data('autoplay-speed') || 0,
588-
fade: $element.data('fade') === 1,
589-
infinite: $element.data('is-infinite') === 1,
590-
arrows: $element.data('show-arrows') === 1,
591-
dots: $element.data('show-dots') === 1
592-
});
593-
};
594-
});
595-
596-
```
597-
598-
### Add XML configuration to load it on the frontend
599-
600-
Add XML configuration to load it on the frontend, and on the stage, so that you can preview content inside both the block and dynamic block content types.
601-
602-
Add the following configuration to the `etc/di.xml` file in your custom module directory:
603-
604-
``` xml
605-
<type name="Magento\PageBuilder\Model\Config\ContentType\WidgetInitializer">
606-
<arguments>
607-
<argument name="config" xsi:type="array">
608-
<item name="%content-type-name%" xsi:type="array">
609-
<!-- Name is the appearance name -->
610-
<item name="default" xsi:type="array">
611-
<!--required argument-->
612-
<item name="component" xsi:type="string">%{vendor-path}/js/content-type/{content-type-name}/appearance/{appearance-name}/widget%</item>
613-
<!--optional if you need provide some config for your widget-->
614-
<item name="config" xsi:type="array">
615-
<item name="buttonSelector" xsi:type="string">.pagebuilder-slide-button</item>
616-
<item name="showOverlay" xsi:type="string">hover</item>
617-
</item>
618-
<!--optional if you want load widget per appearance-->
619-
<item name="appearance" xsi:type="string">default</item>
620-
</item>
621-
</item>
622-
</argument>
623-
</arguments>
624-
</type>
625-
```
626-
627-
## Rendering issues
628-
629-
The master format can appear on the stage when PageBuilder content is embedded into a CMS block and the block is then added to a page via the block content type. This may cause rendering issues on the stage if your customizations do not support this behavior.
630-
631-
You can easily avoid these potential rendering issues by either:
632-
* [Modifying your preview styles to support your master format.](#modify-preview-styles-to-support-master-format)
633-
* [Copying your master format styles to the preview styles.](#copy-master-format-styles-to-preview-styles)
634-
635-
### Modify preview styles to support master format
636-
637-
Depending on the complexity of your customizations, everything may render correctly without any modification to the preview styles to support your master format.
638-
639-
### Copy master format styles to preview styles
640-
641-
If you have a very complex content type with a substantially different preview and master formats, copying your master format styles to the preview styles is the best and most efficient option.
642-
643-
If you are customizing a preview renderer that can contain PageBuilder content, such as the native block content type, you must invoke the widget initializer logic to cause the master format content to initialize correctly. To accomplish this, include the widget initializer in your component and invoke it with the configuration.
644-
645-
**Example:**
646-
647-
For a container that renders master format content, add an `afterRender` binding to initialize the widgets:
648-
649-
``` html
650-
<div html="someVariable" afterRender="initializeWidgets"/>
651-
```
652-
653-
Your component's `initializeWidgets` method would resemble:
654-
655-
``` javascript
656-
define(["Magento_PageBuilder/js/widget-initializer", "Magento_PageBuilder/js/config"], function (widgetInitializer, config) {
657-
return {
658-
initializeWidgets: function initializeWidgets() {
659-
widgetInitializer({
660-
config: config.getConfig("widgets")
661-
});
662-
}
663-
};
664-
});
665-
```

app/code/Magento/PageBuilder/docs/content-type-preview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
1. [Store component master format as widget directive]
2424
1. [Use the block chooser UI component]
2525
1. [Use the inline text editing component]
26-
1. **Render a backend content type preview**
26+
1. [Render a backend content type preview]
2727
1. [Custom Toolbar]
2828
1. [Full width page layouts]
29+
1. [Add custom logic to content types]
2930
5. [Roadmap and known issues]
3031
6. [How to create custom PageBuilder content type container]
3132

@@ -53,11 +54,10 @@
5354
[Render a backend content type preview]: content-type-preview.md
5455
[Custom Toolbar]: toolbar.md
5556
[Full width page layouts]: full-width-page-layouts.md
56-
[Add image uploader to content type]: image-uploader.md
57+
[Add custom logic to content types]: add-custom-logic.md
5758
[Roadmap and Known Issues]: roadmap.md
5859
[How to create custom PageBuilder content type container]: how-to-create-custom-content-type-container.md
5960

60-
6161
## What's in this topic
6262
This topic describes how to use the `RenderPool` on the stage to render a backend [content type] preview.
6363

0 commit comments

Comments
 (0)