Skip to content

Commit a97accd

Browse files
committed
Embedded object Include function added
1 parent 4893fef commit a97accd

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@
2727
"require-dev": {
2828
"phpunit/phpunit": "^9.0",
2929
"phpunit/php-code-coverage": "^8.0",
30-
"sami/sami": "^4.1"
30+
"sami/sami": "^4.1",
31+
"contentstack/utils": "dev-master"
3132
},
3233
"require": {
3334
"php" : ">=5.5.0"
34-
}
35+
},
36+
"repositories": [
37+
{
38+
"type": "path",
39+
"url": "../contentstack-utils-php/"
40+
}
41+
]
3542
}

src/contentstack.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
namespace Contentstack;
1616

1717
use Contentstack\Stack\Stack;
18+
use Contentstack\Utils\Utils;
19+
use Contentstack\Utils\Model\Option;
1820

1921
require_once __DIR__ . '/lib/models/stack.php';
2022

@@ -48,4 +50,14 @@ public static function Stack($api_key = '',
4850
) {
4951
return new Stack($api_key, $access_token, $environment, $region);
5052
}
53+
54+
public static function renderContent(string $content, Option $option): string
55+
{
56+
return Utils::renderContent($content, $option);
57+
}
58+
59+
public static function renderContents(array $contents, Option $option): array
60+
{
61+
return Utils::renderContents($contents, $option);
62+
}
5163
}

src/lib/models/base_query.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,21 @@ public function includeContentType()
357357
return $this->queryObject;
358358
}
359359

360+
/**
361+
* To include Embedded Items along with entries
362+
*
363+
* @return Query
364+
* */
365+
public function includeEmbeddedItems()
366+
{
367+
$this->queryObject->_query = call_user_func(
368+
'contentstackAddBoolean',
369+
'include_embedded_items',
370+
$this->queryObject->_query
371+
);
372+
return $this->queryObject;
373+
}
374+
360375
/**
361376
* To include the count of entries based on the results
362377
*

test/EntriesTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPUnit\Framework\TestCase;
99
use Contentstack\Support\Utility;
1010
use Contentstack\Contentstack;
11+
use Contentstack\Utils\Model\Option;
1112

1213
class EntriesTest extends TestCase {
1314
public static $rest;
@@ -149,6 +150,14 @@ public function testFindIncludeContentType() {
149150
$this->assertTrue($_entries[1]['uid'] === CT_ContentType);
150151
}
151152

153+
public function testFindIncludeEmbeddedItems() {
154+
$_entries = self::$Stack->ContentType(CT_ContentType)->Query()->toJSON()->includeEmbeddedItems()->find();
155+
for($i = 0; $i < count($_entries[0]); $i++) {
156+
$embedded = Contentstack::renderContent('', new Option($_entries[0][$i]));
157+
}
158+
$this->assertArrayHasKey(0, $_entries);
159+
$this->assertTrue((count($_entries[0]) === ENTRY_COUNT));
160+
}
152161
public function testFindIncludeReferenceContentTypeUID() {
153162
$_entries = self::$Stack->ContentType(CT_ContentType)->Query()->toJSON()->includeReferenceContentTypeUID()->find();
154163
$_flag = "false";

0 commit comments

Comments
 (0)