-
Notifications
You must be signed in to change notification settings - Fork 480
Expand file tree
/
Copy pathManageCollectionChildren.php
More file actions
88 lines (72 loc) · 2.64 KB
/
Copy pathManageCollectionChildren.php
File metadata and controls
88 lines (72 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace Lunar\Admin\Filament\Resources\CollectionResource\Pages;
use Filament\Actions\ViewAction;
use Filament\Schemas\Schema;
use Filament\Support\Facades\FilamentIcon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Events\ChildCollectionCreated;
use Lunar\Admin\Filament\Resources\CollectionResource;
use Lunar\Admin\Support\Pages\BaseManageRelatedRecords;
use Lunar\Admin\Support\Tables\Actions\Collections\CreateChildCollection;
class ManageCollectionChildren extends BaseManageRelatedRecords
{
protected static string $resource = CollectionResource::class;
protected static string $relationship = 'children';
public function getTitle(): string|Htmlable
{
return __('lunarpanel::collection.pages.children.label');
}
public static function getNavigationIcon(): ?string
{
return FilamentIcon::resolve('lunar::collections');
}
public static function getNavigationLabel(): string
{
return __('lunarpanel::collection.pages.children.label');
}
public function getBreadcrumbs(): array
{
$record = $this->getRecord();
$crumbs = static::getResource()::getCollectionBreadcrumbs($record);
$crumbs[] = $this->getBreadcrumb();
return $crumbs;
}
public function getBreadcrumb(): string
{
return __('lunarpanel::collection.pages.children.label');
}
public function form(Schema $schema): Schema
{
return $schema;
}
public function table(Table $table): Table
{
return parent::table($table);
}
protected function getDefaultTable(Table $table): Table
{
$record = $this->getOwnerRecord();
return $table->columns([
TextColumn::make('attribute_data.name')
->label(
__('lunarpanel::collection.pages.children.table.name.label')
)
->formatStateUsing(fn (Model $record): string => $record->attr('name')),
TextColumn::make('children_count')->counts('children')
->label(
__('lunarpanel::collection.pages.children.table.children_count.label')
),
])->recordActions([
ViewAction::make()->url(function (Model $record) {
return CollectionResource::getUrl('edit', ['record' => $record]);
}),
])->headerActions([
CreateChildCollection::make('createChildCollection')->after(
fn () => ChildCollectionCreated::dispatch($this->getRecord())
),
]);
}
}