Skip to content

Commit 63b8b1e

Browse files
Added reference support for PHP SDK
1 parent 3622f7b commit 63b8b1e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Stack/Stack.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ public function ImageTrasform($url, $parameters)
142142
public function LivePreviewQuery($parameters) {
143143
$this->live_preview['live_preview'] = $parameters['live_preview'] ?? 'init';
144144
$this->live_preview['content_type_uid'] = $parameters['content_type_uid'] ?? null;
145+
$this->live_preview['entry_uid'] = $parameters['entry_uid'] ?? null;
146+
if(array_key_exists('content_type_uid',$parameters) && array_key_exists('entry_uid',$parameters)){
147+
148+
$this->ContentType($parameters['content_type_uid'])->Entry($parameters['entry_uid'])->fetch();
149+
}
145150
}
146151

147152
/**

src/Support/Utility.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ public static function wrapResult($result = '', $queryObject = '')
378378
public static function contentstackRequest($queryObject = '', $type = '')
379379
{
380380
$server_output = '';
381+
STATIC $live_response = ''; //static variable
382+
STATIC $non_live_response = '';
383+
STATIC $live_response_decode = '';
384+
STATIC $entry_uid = '';
385+
STATIC $content_type_uid = '';
381386

382387
if ($queryObject) {
383388
if (Utility::isLivePreview($queryObject)) {
@@ -414,6 +419,19 @@ public static function contentstackRequest($queryObject = '', $type = '')
414419
// close the curl
415420
curl_close($http);
416421
if ($httpcode > 199 && $httpcode < 300) {
422+
if (!Utility::isLivePreview($queryObject)) {
423+
$result = json_decode($response, true);
424+
Utility::to_render_content($result, $entry_uid, $live_response_decode);
425+
$response = json_encode($result, true);
426+
427+
}
428+
else
429+
{
430+
$entry_uid = $queryObject->entryUid;
431+
$content_type_uid = $queryObject->contentType->uid;
432+
$live_response_decode = json_decode($response, true);
433+
434+
}
417435
// wrapper the server result
418436
$response = Utility::wrapResult($response, $queryObject);
419437
} else {
@@ -423,6 +441,19 @@ public static function contentstackRequest($queryObject = '', $type = '')
423441
return $response;
424442
}
425443

444+
public static function to_render_content(&$resp, $entry_uid, $live_response_decode ){
445+
if (is_array($resp)) {
446+
if(array_key_exists('uid', $resp) && $resp['uid'] == $entry_uid){
447+
$resp = $live_response_decode;
448+
}else
449+
{
450+
foreach ($resp as $key => $value) {
451+
Utility::to_render_content($resp[$key], $entry_uid, $live_response_decode);
452+
}
453+
}
454+
}
455+
}
456+
426457
/**
427458
* Validate the key is set or not
428459
*

0 commit comments

Comments
 (0)