Skip to content

Commit

Permalink
Merge pull request #106 from Kentico/fix/97
Browse files Browse the repository at this point in the history
Extend InlineLinkedItemsResolverInterface.resolveInlineLinkedItems with linked items.

The changes were tested in the wrapper by @stevie-mccomb.
  • Loading branch information
Simply007 authored Nov 8, 2021
2 parents c69006f + 542d9fb commit 22e2083
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Kentico/Kontent/Delivery/DefaultMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ public function resolveBrokenLinkUrl()
*
* @param string $input input html of inline linked items.
* @param mixed $item data for inline linked items.
* @param mixed|null $linkedItems JSON response containing nested linked items
*
* @return string
*/
public function resolveInlineLinkedItems($input, $item)
public function resolveInlineLinkedItems($input, $item, $linkedItems)
{
if(isset($item) && strpos($input, $item->system->codename) !== false){
return $input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ interface InlineLinkedItemsResolverInterface
*
* @param string $input input html of inline linked items.
* @param mixed $item data for inline linked items.
* @param mixed|null $linkedItems JSON response containing nested linked items
*
* @return string
*/
public function resolveInlineLinkedItems($input, $item);
public function resolveInlineLinkedItems($input, $item, $linkedItems);
}
2 changes: 1 addition & 1 deletion src/Kentico/Kontent/Delivery/ModelBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private function resolveLinkedItem($linkedItem, $linkedItems, $processedItems)
$linkedItemsArray = get_object_vars($linkedItems);
$linkedItemData = array_merge($linkedItemsArray, $processedItems);
if (isset($linkedItemData[$itemCodeName])) {
$linkedItem->outertext = $this->inlineLinkedItemsResolver->resolveInlineLinkedItems($linkedItem->outertext, $linkedItemData[$itemCodeName]);
$linkedItem->outertext = $this->inlineLinkedItemsResolver->resolveInlineLinkedItems($linkedItem->outertext, $linkedItemData[$itemCodeName], $linkedItems);
}
}
return $linkedItem->outertext;
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/DefaultMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function test_ResolveInlineLinkedItems_ItemNull_returnEmptyString()
{
$mapper = new DefaultMapper();
$input = '<object type=\"application/kenticocloud\" data-type=\"item\" data-codename=\"modular_item_1\"></object>';
$result = $mapper->resolveInlineLinkedItems($input, null);
$result = $mapper->resolveInlineLinkedItems($input, null, null);

$this->assertTrue(is_string($result));
$this->assertEmpty($result);
Expand All @@ -74,7 +74,7 @@ public function test_ResolveInlineLinkedItems_ItemValid_returnInput()
$input = '<object type=\"application/kenticocloud\" data-type=\"item\" data-codename=\"modular_item_1\"></object>';
$itemJson = file_get_contents('./tests/Unit/Data/SimpleItem.json');
$item = json_decode($itemJson);
$result = $mapper->resolveInlineLinkedItems($input, $item);
$result = $mapper->resolveInlineLinkedItems($input, $item, null);

$this->assertTrue(is_string($result));
$this->assertEquals($input, $result);
Expand Down
6 changes: 4 additions & 2 deletions tests/Unit/ModelBinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public function test_BindModel_MockImplementation_InlineLinkedItemsResolved()
$inlineLinkedItemsResolver
->expects($this->exactly(3))
->method('resolveInlineLinkedItems')
->will($this->returnCallback(function ($input, $item) {
->will($this->returnCallback(function ($input, $item, $linkedItems) {
$this->assertCount(2, get_object_vars($linkedItems));
return '<div>' . $item->system->name . '</div>';
}));

Expand Down Expand Up @@ -120,7 +121,8 @@ public function test_BindModel_MockImplementation_WorkflowStepNotSetForComponent
$inlineLinkedItemsResolver
->expects($this->exactly(2))
->method('resolveInlineLinkedItems')
->will($this->returnCallback(function ($input, $item) {
->will($this->returnCallback(function ($input, $item, $linkedItems) {
$this->assertCount(2, get_object_vars($linkedItems));
if($item->system->codename == 'n8bf1055d_7b61_0180_e1c6_3a09d88f0396') {
$this->assertFalse(isset($item->system->workflow_step));
} else {
Expand Down

0 comments on commit 22e2083

Please sign in to comment.