Skip to content

Commit 0eaf037

Browse files
committed
PB-341: Save content as template
- Final bug fixes
1 parent 857cd87 commit 0eaf037

File tree

8 files changed

+29
-20
lines changed

8 files changed

+29
-20
lines changed

app/code/Magento/PageBuilder/Controller/Adminhtml/Template/Save.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Magento\PageBuilder\Api\TemplateRepositoryInterface;
2424
use Magento\PageBuilder\Model\TemplateFactory;
2525
use Psr\Log\LoggerInterface;
26+
use \Magento\MediaStorage\Helper\File\Storage\Database;
2627

2728
/**
2829
* Save a template within template manager
@@ -68,6 +69,11 @@ class Save extends Action implements HttpPostActionInterface
6869
*/
6970
private $imageContentFactory;
7071

72+
/**
73+
* @var Database
74+
*/
75+
private $mediaStorage;
76+
7177
/**
7278
* @param Context $context
7379
* @param LoggerInterface $logger
@@ -77,6 +83,7 @@ class Save extends Action implements HttpPostActionInterface
7783
* @param Filesystem $filesystem
7884
* @param ImageContentValidator $imageContentValidator
7985
* @param ImageContentFactory $imageContentFactory
86+
* @param Database $mediaStorage
8087
*/
8188
public function __construct(
8289
Context $context,
@@ -86,7 +93,8 @@ public function __construct(
8693
SearchCriteriaBuilder $searchCriteriaBuilder,
8794
Filesystem $filesystem,
8895
ImageContentValidator $imageContentValidator,
89-
ImageContentFactory $imageContentFactory
96+
ImageContentFactory $imageContentFactory,
97+
Database $mediaStorage
9098
) {
9199
parent::__construct($context);
92100

@@ -97,6 +105,7 @@ public function __construct(
97105
$this->filesystem = $filesystem;
98106
$this->imageContentValidator = $imageContentValidator;
99107
$this->imageContentFactory = $imageContentFactory;
108+
$this->mediaStorage = $mediaStorage;
100109
}
101110

102111
/**
@@ -237,6 +246,13 @@ private function storePreviewImage(RequestInterface $request) : ?string
237246
$decodedImage
238247
);
239248

249+
// If the media storage is set to DB also save the file into the DB
250+
if ($this->mediaStorage->checkDbUsage()) {
251+
$this->mediaStorage->saveFile(
252+
$filePath
253+
);
254+
}
255+
240256
// Store the preview image within the new entity
241257
return $filePath;
242258
}

app/code/Magento/PageBuilder/etc/adminhtml/menu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
99
<menu>
10-
<add id="Magento_PageBuilder::templates" title="Templates" translate="title" module="Magento_PageBuilder" sortOrder="100" parent="Magento_Backend::content_elements" action="pagebuilder/template" resource="Magento_PageBuilder::templates"/>
10+
<add id="Magento_PageBuilder::templates" title="Templates" translate="title" module="Magento_PageBuilder" sortOrder="100" parent="Magento_Backend::content_elements" dependsOnConfig="cms/pagebuilder/enabled" action="pagebuilder/template" resource="Magento_PageBuilder::templates"/>
1111
</menu>
1212
</config>

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/buttons/preview.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/row/preview.js

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/modal/template-manager-modal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ define([
4141
*/
4242
applySelected: function (template) {
4343
if (template) {
44-
this.stage.rootContainer.children([]);
44+
// Destroy the old content in the stage
45+
this.stage.pageBuilder.destroy();
4546
$('body').trigger('processStart');
4647

4748
stageBuilder(this.stage, template).then(function () {

app/code/Magento/PageBuilder/view/adminhtml/web/js/template-manager.js

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/row/preview.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ export default class Preview extends PreviewCollection {
9292
this.buildJarallax();
9393
}
9494
});
95-
events.on(`stage:${this.contentType.stageId}:fullScreenModeChangeAfter`, () => {
96-
_.delay(() => {
97-
this.buildJarallax();
98-
}, 350);
99-
});
10095
}
10196

10297
/**

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/template-manager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import alertDialog from "Magento_PageBuilder/js/modal/confirm-alert";
1010
import templateManagerSave from "Magento_PageBuilder/js/modal/template-manager-save";
1111
import promptContentTmpl from "text!Magento_PageBuilder/template/modal/template-manager/save-content-modal.html";
1212
import registry from "uiRegistry";
13+
import _ from "underscore";
1314
import {isAllowed, resources} from "./acl";
1415
import Config from "./config";
1516
import Stage from "./stage";
@@ -169,7 +170,7 @@ function createCapture(stage: Stage) {
169170
function disableParallax(stageElement: Element): ResetRowInterface[] {
170171
const rowsToReset: ResetRowInterface[] = [];
171172
const parallaxRows = stageElement.querySelectorAll("[data-jarallax-original-styles]");
172-
parallaxRows.forEach((row: HTMLElement) => {
173+
_.each(parallaxRows, (row: HTMLElement) => {
173174
const originalStyles = row.getAttribute("data-jarallax-original-styles");
174175
const jarallaxStyle = row.style.cssText;
175176
row.style.cssText = originalStyles;
@@ -191,7 +192,7 @@ function disableParallax(stageElement: Element): ResetRowInterface[] {
191192
* @param rows
192193
*/
193194
function restoreParallax(rows: ResetRowInterface[]) {
194-
rows.forEach(({element, styles, container}) => {
195+
_.each(rows, ({element, styles, container}) => {
195196
element.style.cssText = styles;
196197
container.style.display = "";
197198
});

0 commit comments

Comments
 (0)