Skip to content

Commit

Permalink
[5.x] Reuse results of referenceExists inside the structure `TreeBu…
Browse files Browse the repository at this point in the history
…ilder` (#9676)
  • Loading branch information
JohnathonKoster authored Mar 7, 2024
1 parent dae2639 commit 9770ba2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Structures/TreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,19 @@ protected function transformTreeForController($tree)
return collect($tree)->map(function ($item) {
$page = $item['page'];
$collection = $page->collection();
$referenceExists = $page->referenceExists();

return [
'id' => $page->id(),
'entry' => $page->reference(),
'title' => $page->hasCustomTitle() ? $page->title() : null,
'entry_title' => $page->referenceExists() ? $page->entry()->value('title') : null,
'url' => $page->referenceExists() ? $page->url() : null,
'entry_title' => $referenceExists ? $page->entry()->value('title') : null,
'url' => $referenceExists ? $page->url() : null,
'edit_url' => $page->editUrl(),
'can_delete' => $page->referenceExists() ? User::current()->can('delete', $page->entry()) : true,
'can_delete' => $referenceExists ? User::current()->can('delete', $page->entry()) : true,
'slug' => $page->slug(),
'status' => $page->referenceExists() ? $page->status() : null,
'redirect' => $page->referenceExists() ? $page->entry()->get('redirect') : null,
'status' => $referenceExists ? $page->status() : null,
'redirect' => $referenceExists ? $page->entry()->get('redirect') : null,
'collection' => ! $collection ? null : [
'handle' => $collection->handle(),
'title' => $collection->title(),
Expand Down

0 comments on commit 9770ba2

Please sign in to comment.