|
4 | 4 |
|
5 | 5 | namespace Relaticle\CustomFields\Filament\Integration\Components\Infolists; |
6 | 6 |
|
7 | | -use Filament\Infolists\Components\Entry; |
8 | | -use Filament\Infolists\Components\TextEntry as BaseTextEntry; |
| 7 | +use Filament\Infolists\Components\ViewEntry; |
| 8 | +use Relaticle\CustomFields\Enums\CustomFieldsFeature; |
| 9 | +use Relaticle\CustomFields\FeatureSystem\FeatureManager; |
9 | 10 | use Relaticle\CustomFields\Filament\Integration\Base\AbstractInfolistEntry; |
10 | | -use Relaticle\CustomFields\Filament\Integration\Concerns\Shared\ConfiguresBadgeColors; |
| 11 | +use Relaticle\CustomFields\Models\Contracts\HasCustomFields; |
11 | 12 | use Relaticle\CustomFields\Models\CustomField; |
12 | | -use Relaticle\CustomFields\Services\ValueResolver\LookupMultiValueResolver; |
13 | 13 |
|
14 | 14 | final class MultiChoiceEntry extends AbstractInfolistEntry |
15 | 15 | { |
16 | | - use ConfiguresBadgeColors; |
17 | | - |
18 | | - public function __construct( |
19 | | - private readonly LookupMultiValueResolver $valueResolver |
20 | | - ) {} |
21 | | - |
22 | | - public function make(CustomField $customField): Entry |
| 16 | + public function make(CustomField $customField): ViewEntry |
23 | 17 | { |
24 | | - $entry = BaseTextEntry::make($customField->getFieldName()) |
25 | | - ->label($customField->name); |
26 | | - |
27 | | - $entry = $this->applyBadgeColorsIfEnabled($entry, $customField); |
| 18 | + $options = $customField->options->pluck('name', 'id')->all(); |
| 19 | + $optionColors = $this->resolveOptionColors($customField); |
| 20 | + |
| 21 | + return ViewEntry::make($customField->getFieldName()) |
| 22 | + ->label($customField->name) |
| 23 | + ->view('custom-fields::infolists.checkbox-list-entry') |
| 24 | + ->state(fn (HasCustomFields $record): array => [ |
| 25 | + 'options' => $options, |
| 26 | + 'selected' => $record->getCustomFieldValue($customField) ?? [], |
| 27 | + 'optionColors' => $optionColors, |
| 28 | + ]); |
| 29 | + } |
28 | 30 |
|
29 | | - return $entry->state(fn (mixed $record): array => $this->valueResolver->resolve($record, $customField)); |
| 31 | + /** @return array<int, string> */ |
| 32 | + private function resolveOptionColors(CustomField $customField): array |
| 33 | + { |
| 34 | + if (! FeatureManager::isEnabled(CustomFieldsFeature::FIELD_OPTION_COLORS) |
| 35 | + || ! $customField->settings->enable_option_colors |
| 36 | + || $customField->lookup_type) { |
| 37 | + return []; |
| 38 | + } |
| 39 | + |
| 40 | + return $customField->options |
| 41 | + ->filter(fn ($option): bool => filled($option->settings->color)) |
| 42 | + ->pluck('settings.color', 'id') |
| 43 | + ->all(); |
30 | 44 | } |
31 | 45 | } |
0 commit comments