|
12 | 12 | use Filament\Support\Enums\Size; |
13 | 13 | use Filament\Support\Enums\Width; |
14 | 14 | use Illuminate\Contracts\View\View; |
| 15 | +use Illuminate\Database\Eloquent\Collection; |
| 16 | +use Livewire\Attributes\Computed; |
| 17 | +use Livewire\Attributes\On; |
15 | 18 | use Livewire\Component; |
16 | 19 | use Relaticle\CustomFields\CustomFields; |
17 | 20 | use Relaticle\CustomFields\Filament\Management\Schemas\FieldForm; |
18 | 21 | use Relaticle\CustomFields\Livewire\Concerns\CreatesCustomFields; |
19 | | -use Relaticle\CustomFields\Livewire\Concerns\ManagesFields; |
20 | 22 | use Relaticle\CustomFields\Models\CustomFieldSection; |
21 | 23 |
|
22 | 24 | /** |
23 | 25 | * Livewire component for managing custom fields when sections are disabled. |
| 26 | + * |
| 27 | + * Shows ALL fields for the entity type regardless of which section they belong to. |
| 28 | + * New fields are created in the default section. |
24 | 29 | */ |
25 | 30 | final class ManageFieldsWithoutSections extends Component implements HasActions, HasForms |
26 | 31 | { |
27 | 32 | use CreatesCustomFields; |
28 | 33 | use InteractsWithActions; |
29 | 34 | use InteractsWithForms; |
30 | | - use ManagesFields; |
31 | 35 |
|
32 | 36 | public string $entityType; |
33 | 37 |
|
| 38 | + /** The default section used for creating new fields */ |
34 | 39 | public CustomFieldSection $section; |
35 | 40 |
|
| 41 | + /** |
| 42 | + * Get ALL fields for the entity type, regardless of section. |
| 43 | + */ |
| 44 | + #[Computed] |
| 45 | + public function fields(): Collection |
| 46 | + { |
| 47 | + return CustomFields::newCustomFieldModel() |
| 48 | + ->newQuery() |
| 49 | + ->withDeactivated() |
| 50 | + ->where('entity_type', $this->entityType) |
| 51 | + ->orderBy('sort_order') |
| 52 | + ->get(); |
| 53 | + } |
| 54 | + |
| 55 | + #[On('field-width-updated')] |
| 56 | + public function fieldWidthUpdated(int|string $fieldId, int $width): void |
| 57 | + { |
| 58 | + $model = CustomFields::newCustomFieldModel(); |
| 59 | + $model->where($model->getKeyName(), $fieldId)->update(['width' => $width]); |
| 60 | + unset($this->fields); |
| 61 | + } |
| 62 | + |
| 63 | + #[On('field-deleted')] |
| 64 | + public function fieldDeleted(): void |
| 65 | + { |
| 66 | + unset($this->fields); |
| 67 | + } |
| 68 | + |
| 69 | + #[On('fields-reordered')] |
| 70 | + public function fieldsReordered(): void |
| 71 | + { |
| 72 | + unset($this->fields); |
| 73 | + } |
| 74 | + |
36 | 75 | public function updateFieldsOrder(array $fields): void |
37 | 76 | { |
38 | 77 | $model = CustomFields::newCustomFieldModel(); |
|
0 commit comments