Skip to content

Commit 3bc7df3

Browse files
committed
Add properties to OnResourceMagicPreview event + small tweaks and comments
1 parent 23f83a1 commit 3bc7df3

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

assets/components/magicpreview/js/preview.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,28 @@
3636
return btns;
3737
},
3838

39+
/**
40+
* Run when the preview button is clicked
41+
* @returns {boolean}
42+
*/
3943
mpPreview: function() {
4044
var o = this.config;
4145
if (!o.formpanel) return false;
4246

4347
MODx.util.Progress.reset();
48+
49+
// Get the resource form panel
4450
o.form = Ext.getCmp(o.formpanel);
4551
if (!o.form) return false;
4652

4753
if (o.previewWindow && !o.previewWindow.closed) {
4854
o.previewWindow.focus();
49-
}
50-
else {
55+
} else {
5156
o.previewWindow = window.open(previewUrl + '#loading', 'MagicPreview_' + MagicPreviewResource)
5257
o.previewWindow.opener = window; // Pass reference to the main window
5358
}
5459

60+
// Check if all the fields in the form are valid
5561
var f = o.form.getForm ? o.form.getForm() : o.form;
5662
var isv = true;
5763
if (f.items && f.items.items) {
@@ -66,12 +72,14 @@
6672
}
6773
}
6874

75+
// If the form is valid, push the data to the preview processor
6976
if (isv) {
7077
var originalAction = o.form.baseParams['action'],
7178
originalUrl = o.form.url;
7279
f.baseParams['action'] = 'resource/preview';
7380
f.url = MagicPreviewConfig.assetsUrl + 'connector.php';
7481

82+
// If the response from the processor is successful, set the new location in the preview window
7583
o.form.on('success', function (r) {
7684
f.baseParams['action'] = originalAction;
7785
f.url = originalUrl;
@@ -81,13 +89,14 @@
8189
}
8290

8391
}, this);
92+
93+
// Submit the form to the processor
8494
o.form.submit({
8595
headers: {
8696
'Powered-By': 'MODx'
87-
, 'modAuth': MODx.siteId
97+
,'modAuth': MODx.siteId
8898
}
8999
});
90-
91100
}
92101
},
93102

core/components/magicpreview/elements/plugins/magicpreview.plugin.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?php
2+
23
/**
34
* @var modX $modx
45
*/
5-
66
$path = $modx->getOption('magicpreview.core_path', null, $modx->getOption('core_path') . 'components/magicpreview/');
7-
$service =& $modx->getService('magicpreview', 'MagicPreview', $path . '/model/magicpreview/');
8-
7+
$service = $modx->getService('magicpreview', 'MagicPreview', $path . '/model/magicpreview/');
98
if (!($service instanceof MagicPreview)) {
109
return 'Could not load MagicPreview service.';
1110
}
1211

1312
switch ($modx->event->name) {
1413
case 'OnDocFormRender':
14+
/** @var modResource|\MODX\Revolution\modResource $resource */
1515
if ($resource->get('id') > 0) {
1616
// Determine MODX version and add body class to assist with styling
1717
$versionCls = 'magicpreview_modx2';

core/components/magicpreview/processors/resource/PreviewTrait.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public function fireBeforeSaveEvent()
1212
{
1313
// Invoke an event to allow other modules to prepare/modify the resource before preview.
1414
$this->modx->invokeEvent('OnResourceMagicPreview', [
15-
'resource' => $this->object
15+
'resource' => $this->object,
16+
'properties' => $this->getProperties(),
1617
]);
1718

1819
$this->failedSuccessfully = true;

0 commit comments

Comments
 (0)