diff --git a/src/Structures/Page.php b/src/Structures/Page.php index eebcccb169a..207d3eeeead 100644 --- a/src/Structures/Page.php +++ b/src/Structures/Page.php @@ -201,6 +201,11 @@ public function slug() return optional($this->entry())->slug(); } + public function origin() + { + return optional($this->entry())->origin(); + } + public function uri() { if ($this->url) { diff --git a/tests/API/APITest.php b/tests/API/APITest.php index 64737f01e4a..a9d7b1e7ae7 100644 --- a/tests/API/APITest.php +++ b/tests/API/APITest.php @@ -250,6 +250,29 @@ public function it_filters_published_entries_in_nav_route_by_default() $this->assertEndpointDataCount('/api/navs/footer/tree', 2); } + #[Test] + public function it_gets_origin_id_in_nav_route_when_an_item_is_not_linked_to_an_entry() + { + Facades\Config::set('statamic.api.resources.navs', true); + + Facades\Collection::make('pages')->save(); + + $nav = Facades\Nav::make('footer'); + $nav->makeTree('en', [ + ['entry' => 'one'], + ['title' => 'Balki Bartokomous', 'url' => 'https://balki.com'], + ])->save(); + $nav->save(); + + Facades\Entry::make()->collection('pages')->id('one')->slug('one')->published(true)->save(); + + $this + ->get('/api/navs/footer/tree?fields=title,origin_id') + ->assertSuccessful() + ->assertJsonPath('data.1.page.title', 'Balki Bartokomous') + ->assertJsonPath('data.1.page.origin_id', null); + } + #[Test] public function it_filters_by_taxonomy_terms() {