Skip to content

Commit 2b5535f

Browse files
committed
fix isssue with image save
1 parent a0f90d6 commit 2b5535f

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

Diff for: core/components/fred/src/Endpoint/Ajax/SaveContent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function process(): string
236236
return $this->failure($this->modx->lexicon('fred.fe.err.resource_save'));
237237
}
238238
// unify resource rendering
239-
$renderResource = new \Fred\RenderResource($this->object, $this->modx, $this->body['data']);
239+
$renderResource = new \Fred\RenderResource($this->object, $this->modx, $this->body['data'], $this->body['pageSettings']);
240240
if (!$renderResource->render()) {
241241
return $this->failure($this->modx->lexicon('fred.fe.err.resource_save'));
242242
}

Diff for: core/components/fred/src/RenderResource.php

+25-17
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ final class RenderResource
3939
/** @var array */
4040
public $data = [];
4141

42+
/** @var array */
43+
public $pageSettings = [];
44+
4245
/** @var array */
4346
private $elementOptions = [];
4447

4548
/** @var array */
4649
private $elementCache = [];
4750

48-
public function __construct(modResource $resource, modX $modx, $data = [])
51+
public function __construct(modResource $resource, modX $modx, $data = [], $pageSettings = [])
4952
{
5053
$this->resource = $resource;
5154
$this->modx = $modx;
@@ -60,6 +63,7 @@ public function __construct(modResource $resource, modX $modx, $data = [])
6063
if (empty($this->data) && !empty($this->resource->content)) {
6164
$this->setDefaults();
6265
}
66+
$this->pageSettings = $pageSettings;
6367
$elements = [];
6468
$this->gatherElements($elements, $this->data);
6569

@@ -213,7 +217,6 @@ public function render(): bool
213217

214218
$c->where(
215219
[
216-
'type' => 'freddropzone',
217220
'TemplateVarTemplates.templateid' => $this->resource->get('template'),
218221
]
219222
);
@@ -224,24 +227,29 @@ public function render(): bool
224227
$mTypes = explode(',', $mTypes);
225228
foreach ($tvs as $tv) {
226229
$tvName = $tv->get('name');
227-
228-
if (isset($this->data[$tvName])) {
230+
// check if TV is in base data or pageSettings
231+
$tvValue = (isset($this->pageSettings['tvs'][$tvName])) ?
232+
$this->pageSettings['tvs'][$tvName] :
233+
($this->data[$tvName] ?? null);
234+
if (isset($tvValue)) {
229235
$tvContent = '';
230-
231-
foreach ($this->data[$tvName] as $item) {
232-
try {
233-
$tvContent .= $this->renderElement(
234-
$this->twig->render(
235-
$item['widget'],
236-
$this->mergeSetting(!empty($item['elId']) ? $item['elId'] : '', $item['settings'])
237-
),
238-
$item,
239-
true
240-
);
241-
} catch (\Exception $e) {
236+
if ($tv->type === 'freddropzone' || is_array($tvValue)) {
237+
foreach ($tvValue as $item) {
238+
try {
239+
$tvContent .= $this->renderElement(
240+
$this->twig->render(
241+
$item['widget'],
242+
$this->mergeSetting(!empty($item['elId']) ? $item['elId'] : '', $item['settings'])
243+
),
244+
$item,
245+
true
246+
);
247+
} catch (\Exception $e) {
248+
}
242249
}
250+
} else {
251+
$tvContent = $tvValue;
243252
}
244-
245253
$tvContent = Utils::htmlDecodeTags($tvContent, $parser);
246254
if (in_array($tv->type, $mTypes, true)) {
247255
$this->resource->setTVValue($tvName, $this->reversePreparedOutput($tv, $tvContent, $this->resource));

0 commit comments

Comments
 (0)