Skip to content

Commit c835450

Browse files
committed
allow to retrieve the title of a page in plain_text
1 parent c1aed1b commit c835450

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/Entities/Page.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class Page extends Entity
1313
{
14-
14+
protected string $title = "";
1515
protected array $rawProperties = [];
1616
protected Collection $propertyCollection;
1717
protected DateTime $createdTime;
@@ -29,6 +29,7 @@ private function fillFromRaw(): void
2929
{
3030
$this->fillId();
3131
$this->fillProperties();
32+
$this->fillTitle();
3233
$this->fillCreatedTime();
3334
$this->fillLastEditedTime();
3435
}
@@ -44,6 +45,27 @@ private function fillProperties(): void
4445
}
4546
}
4647

48+
private function fillTitle(): void
49+
{
50+
$titleProperty = $this->propertyCollection->filter(function ($property) {
51+
return $property->getType() == "title";
52+
})->first();
53+
54+
if ($titleProperty !== null) {
55+
$rawTitleProperty = $titleProperty->getRawContent();
56+
if (is_array($rawTitleProperty) && count($rawTitleProperty) >= 1) {
57+
if (Arr::exists($rawTitleProperty[0], 'plain_text')) {
58+
$this->title = $rawTitleProperty[0]['plain_text'];
59+
}
60+
}
61+
}
62+
}
63+
64+
public function getTitle(): string
65+
{
66+
return $this->title;
67+
}
68+
4769

4870
public function getProperties(): Collection
4971
{
@@ -52,7 +74,7 @@ public function getProperties(): Collection
5274

5375
public function getProperty(string $propertyName): ?Property
5476
{
55-
$property = $this->propertyCollection->filter(function($property) use($propertyName) {
77+
$property = $this->propertyCollection->filter(function ($property) use ($propertyName) {
5678
return $property->getTitle() == $propertyName;
5779
})->first();
5880

0 commit comments

Comments
 (0)