Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.

Commit 0144602

Browse files
Added some basic support for page child blocks
1 parent 7a0a4b4 commit 0144602

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/Notion/Objects/Page.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,36 @@ class Page extends ObjectBase
1010

1111
protected $parent;
1212

13+
protected $children = [];
14+
1315
public function setParent($type, $id): self
1416
{
1517
$this->parent[$type . '_id'] = $id;
1618

1719
return $this;
1820
}
1921

22+
// TODO: Implement rich text logic
23+
public function addChild($type, $text, $extra = null): self
24+
{
25+
$this->children[] = [
26+
'object' => 'block',
27+
'type' => $type,
28+
$type => [
29+
'text' => [
30+
[
31+
'text' => [
32+
'type' => 'text',
33+
'content' => $text,
34+
],
35+
]
36+
],
37+
],
38+
];
39+
40+
return $this;
41+
}
42+
2043
public function prepareForRequest()
2144
{
2245
$data = [
@@ -34,6 +57,10 @@ public function prepareForRequest()
3457
$data['properties'][$property->name] = $value;
3558
}
3659

60+
if (count($this->children) > 0) {
61+
$data['children'] = $this->children;
62+
}
63+
3764
return $data;
3865
}
3966

@@ -76,7 +103,7 @@ public function save()
76103
];
77104

78105
if ($this->context === 'create') {
79-
$response = $this->notion->getClient()->post('pages', $options);
106+
return $this->notion->getClient()->post('pages', $options);
80107
}
81108
}
82109

0 commit comments

Comments
 (0)