Skip to content

Commit d51bcc2

Browse files
authored
Merge pull request #23 from contentstack/embedded_items
Embedded items feature support added
2 parents 27f8a65 + f77905f commit d51bcc2

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"test": "vendor/bin/phpunit"
3535
},
3636
"require": {
37-
"php" : ">=5.5.0"
37+
"php" : ">=5.5.0",
38+
"contentstack/utils": "^1.0"
3839
}
3940
}

src/Contentstack.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
namespace Contentstack;
1616

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

1922
/**
2023
* Contentstack abstract class to provide access to Stack Object
@@ -36,7 +39,8 @@ abstract class Contentstack
3639
* @param string $access_token : Contentstack Stack ACCESS TOKEN.
3740
* @param string $environment : Environment Name.
3841
* @param array $config : Stack Configuration to provide region.
39-
*
42+
* @param ContentstackRegion $region : Region name of Contentstack.
43+
4044
* @return Stack
4145
* */
4246
public static function Stack($api_key = '',
@@ -46,4 +50,14 @@ public static function Stack($api_key = '',
4650
) {
4751
return new Stack($api_key, $access_token, $environment, $config);
4852
}
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+
}
4963
}

src/Stack/BaseQuery.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,22 @@ 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+
'contentstackReferences',
369+
'include_embedded_items',
370+
$this->queryObject->_query,
371+
["BASE"]
372+
);
373+
return $this->queryObject;
374+
}
375+
360376
/**
361377
* To include the count of entries based on the results
362378
*

test/EntriesTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPUnit\Framework\TestCase;
88
use Contentstack\Support\Utility;
99
use Contentstack\Contentstack;
10+
use Contentstack\Utils\Model\Option;
1011

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

152+
public function testFindIncludeEmbeddedItems() {
153+
$_entries = self::$Stack->ContentType('rte_embed')->Query()->toJSON()->includeEmbeddedItems()->find();
154+
155+
for($i = 0; $i < count($_entries[0]); $i++) {
156+
print_r($_entries[0][$i]["rich_text_editor"]);
157+
if ($_entries[0][$i]["rich_text_editor"] !== "undefined") {
158+
$embedded = Contentstack::renderContent($_entries[0][$i]["rich_text_editor"], new Option($_entries[0][$i]));
159+
}
160+
}
161+
$this->assertArrayHasKey(0, $_entries);
162+
163+
}
151164
public function testFindIncludeReferenceContentTypeUID() {
152165
$_entries = self::$Stack->ContentType(CT_ContentType)->Query()->toJSON()->includeReferenceContentTypeUID()->find();
153166
$_flag = "false";

0 commit comments

Comments
 (0)