Skip to content

Commit 9b17c08

Browse files
author
Artem Stepin
committed
fixed issue creating sub pages
1 parent 98842c6 commit 9b17c08

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/Api/Content.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ public function create(AbstractContent $content): AbstractContent
140140
],
141141
];
142142

143+
if (count($content->getAncestors()) > 0) {
144+
$ancestorsData = array_map(static function(int $id) {
145+
return ['id' => $id];
146+
}, $content->getAncestors());
147+
148+
$data['ancestors'] = $ancestorsData;
149+
}
150+
143151
/* attach content to content */
144152
if (null !== $content->getContainerId()) {
145153
$data['container'] = [
@@ -313,4 +321,4 @@ private function deserializeContent(array $decodedData): AbstractContent
313321

314322
return $content;
315323
}
316-
}
324+
}

src/Entity/AbstractContent.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ abstract class AbstractContent
1414

1515
private ?string $content = null;
1616

17+
/**
18+
* @var int[]
19+
*/
20+
private array $ancestors = [];
21+
1722
private int $version = 1;
1823
/**
1924
* @var array<string, string> $children
@@ -176,6 +181,7 @@ public function createComment(string $comment): ContentComment
176181
$contentComment->setContainerId($this->getId());
177182
$contentComment->setContainerType($this->getType());
178183
$contentComment->setContent($comment);
184+
$contentComment->setSpace($this->getSpace());
179185
return $contentComment;
180186
}
181187

@@ -187,10 +193,10 @@ public function createComment(string $comment): ContentComment
187193
public function createSubpage(string $title, string $body): ContentPage
188194
{
189195
$contentPage = new ContentPage();
190-
$contentPage->setContainerId($this->getId());
191-
$contentPage->setContainerType($this->getType());
196+
$contentPage->addAncestor($this->id);
192197
$contentPage->setContent($body);
193198
$contentPage->setTitle($title);
199+
$contentPage->setSpace($this->getSpace());
194200
return $contentPage;
195201
}
196202

@@ -226,4 +232,32 @@ public function setContainerType(string $containerType): void
226232
$this->containerType = $containerType;
227233
}
228234

229-
}
235+
/**
236+
* @return int[]
237+
*/
238+
public function getAncestors(): array
239+
{
240+
return $this->ancestors;
241+
}
242+
243+
/**
244+
* @param int[] $ancestors
245+
* @return self
246+
*/
247+
public function setAncestors(array $ancestors): self
248+
{
249+
$this->ancestors = $ancestors;
250+
return $this;
251+
}
252+
253+
/**
254+
* @param int $id
255+
* @return self
256+
*/
257+
public function addAncestor(int $id): self
258+
{
259+
$this->ancestors[] = $id;
260+
return $this;
261+
}
262+
263+
}

0 commit comments

Comments
 (0)