Skip to content
22 changes: 22 additions & 0 deletions resources/js/pages/collections/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@
variant="destructive"
@click="deleteTreeBranch(branch, removeBranch)"
/>
<template v-if="branchTreeActions(branch).length">
<DropdownSeparator />
<ItemActions
:url="entriesActionUrl"
:actions="branchTreeActions(branch)"
:item="branch.entry"
v-slot="{ actions }"
>
<DropdownItem
v-for="action in actions"
:key="action.handle"
:text="__(action.title)"
:icon="action.icon"
:variant="action.dangerous ? 'destructive' : undefined"
@click="action.run()"
/>
</ItemActions>
</template>
</template>
</page-tree>

Expand Down Expand Up @@ -397,6 +415,10 @@ export default {
return branch.redirect != null;
},

branchTreeActions(branch) {
return (branch.actions || []).filter((action) => action.handle !== 'delete');
},

createEntry(blueprint, parent) {
let url = `${this.createUrl}?blueprint=${blueprint}`;
if (parent) url += '&parent=' + parent;
Expand Down
23 changes: 17 additions & 6 deletions src/Structures/TreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Structures;

use Statamic\Contracts\Structures\Nav;
use Statamic\Facades\Action;
use Statamic\Facades\Entry;
use Statamic\Facades\Structure;
use Statamic\Facades\User;
Expand Down Expand Up @@ -91,22 +92,32 @@ protected function transformTreeForController($tree)
$page = $item['page'];
$collection = $page->mountedCollection();
$referenceExists = $page->referenceExists();
$entry = $referenceExists ? $page->entry() : null;

$actionContext = ['view' => 'tree'];
if ($collection) {
$actionContext['collection'] = $collection->handle();
}
if ($entry) {
$actionContext['site'] = $entry->locale();
}

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