|
2 | 2 |
|
3 | 3 | namespace CodeWithDennis\FilamentTests\Concerns; |
4 | 4 |
|
| 5 | +use Filament\Actions\Action; |
5 | 6 | use Filament\Resources\Pages\ListRecords; |
6 | 7 | use Filament\Schemas\Schema; |
7 | 8 | use Filament\Tables\Columns\Column; |
8 | 9 | use Filament\Tables\Table; |
| 10 | +use ReflectionClass; |
9 | 11 |
|
10 | 12 | trait InteractsWithResources |
11 | 13 | { |
| 14 | + protected function getPrivateProperty(object $object, string $property): mixed |
| 15 | + { |
| 16 | + $reflection = new ReflectionClass($object); |
| 17 | + $property = $reflection->getProperty($property); |
| 18 | + $property->setAccessible(true); |
| 19 | + |
| 20 | + return $property->getValue($object); |
| 21 | + } |
| 22 | + |
12 | 23 | public function getResourceClass(): ?string |
13 | 24 | { |
14 | 25 | return $this->resourceClass; |
@@ -41,6 +52,18 @@ public function getResourceTableColumns(): array |
41 | 52 | return $this->getResourceTable()->getColumns(); |
42 | 53 | } |
43 | 54 |
|
| 55 | + public function getResourceTableActions(): array |
| 56 | + { |
| 57 | + return $this->getResourceTable()->getActions(); |
| 58 | + } |
| 59 | + |
| 60 | + public function getResourceTableVisibleActions(): array |
| 61 | + { |
| 62 | + return array_filter($this->getResourceTableActions(), function (Action $action) { |
| 63 | + return ! $this->getPrivateProperty($action, 'isHidden'); |
| 64 | + }); |
| 65 | + } |
| 66 | + |
44 | 67 | public function getResourceSortableTableColumns(): array |
45 | 68 | { |
46 | 69 | return array_filter($this->getResourceTableColumns(), fn (Column $column) => $column->isSortable()); |
|
0 commit comments