Skip to content

Commit 4e50027

Browse files
committed
Add getter for page title, to make this more extendable
(cherry picked from commit 2582bed)
1 parent 53f479b commit 4e50027

File tree

10 files changed

+24
-11
lines changed

10 files changed

+24
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ title and full screen image, and the `<x-flexible-content-blocks>` component ren
353353
__Note:__ The `x-flexible-hero` component requires [Alpine.js](https://alpinejs.dev/).
354354

355355
```html
356-
<x-layouts.flexible title="{{ $page->title }}" wide="true">
356+
<x-layouts.flexible title="{{ $page->getTitle() }}" wide="true">
357357
<x-flexible-hero :page="$page" />
358358
<div>
359359
<x-flexible-content-blocks :page="$page">

example/app/Http/PageController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __invoke(Page $page)
2121

2222
return view('pages.index', [
2323
'page' => $page,
24-
'title' => $page->title,
24+
'title' => $page->getTitle(),
2525
]);
2626
}
2727
}

example/app/Http/TranslatablePageController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __invoke(TranslatablePage $page)
2323

2424
return view('translatable-pages.index', [
2525
'page' => $page,
26-
'title' => $page->title,
26+
'title' => $page->getTitle(),
2727
]);
2828
}
2929
}

example/resources/views/pages/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* @var \App\Models\Page $page */
33
@endphp
44

5-
<x-layouts.base title="{{ $page->title }}" wide="true">
5+
<x-layouts.base title="{{ $page->getTitle() }}" wide="true">
66

77
<x-flexible-hero :page="$page" />
88

example/resources/views/translatable-pages/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* @var \App\Models\TranslatablePage $page */
33
@endphp
44

5-
<x-layouts.base title="{{ $page->title }}" wide="true">
5+
<x-layouts.base title="{{ $page->getTitle() }}" wide="true">
66

77
<x-flexible-hero :page="$page" />
88

src/Models/Concerns/HasOverviewAttributesTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function overviewImage(): MorphMany
3333

3434
public function getOverviewTitle(): ?string
3535
{
36-
if (! $this->overview_title && isset($this->title)) {
37-
return $this->title;
36+
if (! $this->overview_title && $this->getTitle()) {
37+
return $this->getTitle();
3838
}
3939
if (! $this->overview_title && isset($this->seo_title)) {
4040
return $this->seo_title;

src/Models/Concerns/HasPageAttributesTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ public function initializeHasPageAttributesTrait(): void
2424
]);
2525
}
2626

27+
/**
28+
* Returns the title of the page
29+
*/
30+
public function getTitle(): ?string
31+
{
32+
return $this->title;
33+
}
34+
2735
/**
2836
* {@inheritDoc}
2937
*/

src/Models/Concerns/HasSEOAttributesTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public function SEOImage(): MorphMany
3737

3838
public function getSEOTitle(): ?string
3939
{
40-
if (! $this->seo_title && isset($this->title)) {
41-
return $this->title;
40+
if (! $this->seo_title && $this->getTitle()) {
41+
return $this->getTitle();
4242
}
4343

4444
return $this->seo_title;

src/Models/Contracts/HasPageAttributes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
interface HasPageAttributes
1515
{
16+
/**
17+
* Returns the title of the page
18+
*/
19+
public function getTitle(): ?string;
20+
1621
/**
1722
* Returns whether the page is published or visible, based on the begin and end publishing dates.
1823
*/

src/View/Components/Hero.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function __construct(HasPageAttributes|HasHeroImageAttributes|HasHeroCall
3333
{
3434
$this->page = $page;
3535

36-
if (isset($page->title)) {
37-
$this->title = $page->title;
36+
if ($page->getTitle()) {
37+
$this->title = $page->getTitle();
3838
}
3939

4040
if (isset($page->intro)) {

0 commit comments

Comments
 (0)