diff --git a/resources/views/livewire/plugins/recipe.blade.php b/resources/views/livewire/plugins/recipe.blade.php index e8ab799..ec53aae 100644 --- a/resources/views/livewire/plugins/recipe.blade.php +++ b/resources/views/livewire/plugins/recipe.blade.php @@ -37,6 +37,7 @@ new class extends Component { public array $configuration = []; public array $xhrSelectOptions = []; public array $searchQueries = []; + public array $multiValues = []; public function mount(): void { @@ -74,6 +75,25 @@ new class extends Component { $this->fillformFields(); $this->data_payload_updated_at = $this->plugin->data_payload_updated_at; + + foreach ($this->configuration_template['custom_fields'] ?? [] as $field) { + if (($field['field_type'] ?? null) !== 'multi_string') { + continue; + } + + $fieldKey = $field['keyname'] ?? $field['key'] ?? $field['name']; + + // Get the existing value from the plugin's configuration + $rawValue = $this->configuration[$fieldKey] ?? ($field['default'] ?? ''); + + $currentValue = is_array($rawValue) ? '' : (string)$rawValue; + + // Split CSV into array for UI boxes + $this->multiValues[$fieldKey] = $currentValue !== '' + ? array_values(array_filter(explode(',', $currentValue))) + : ['']; + } + } public function fillFormFields(): void @@ -129,6 +149,19 @@ new class extends Component { $validated = $this->validate(); $validated['data_payload'] = json_decode(Arr::get($validated,'data_payload'), true); $this->plugin->update($validated); + + foreach ($this->configuration_template as $fieldKey => $field) { + if (($field['field_type'] ?? null) !== 'multi_string') { + continue; + } + + if (!isset($this->multiValues[$fieldKey])) { + continue; + } + + $validated[$fieldKey] = implode(',', array_filter(array_map('trim', $this->multiValues[$fieldKey]))); + } + } protected function validatePollingUrl(): void @@ -258,6 +291,14 @@ new class extends Component { { abort_unless(auth()->user()->plugins->contains($this->plugin), 403); + foreach ($this->configuration_template['custom_fields'] ?? [] as $field) { + $fieldKey = $field['keyname'] ?? $field['key'] ?? $field['name']; + + if ($field['field_type'] === 'multi_string' && isset($this->multiValues[$fieldKey])) { + // Join the boxes into a CSV string, trimming whitespace and filtering empties + $this->configuration[$fieldKey] = implode(',', array_filter(array_map('trim', $this->multiValues[$fieldKey]))); + } + } $configurationValues = []; if (isset($this->configuration_template['custom_fields'])) { foreach ($this->configuration_template['custom_fields'] as $field) { @@ -433,6 +474,22 @@ HTML; $this->loadXhrSelectOptions($fieldKey, $endpoint, $query); } } + + public function addMultiItem(string $fieldKey): void + { + $this->multiValues[$fieldKey][] = ''; + } + + public function removeMultiItem(string $fieldKey, int $index): void + { + unset($this->multiValues[$fieldKey][$index]); + + $this->multiValues[$fieldKey] = array_values($this->multiValues[$fieldKey]); + + if (empty($this->multiValues[$fieldKey])) { + $this->multiValues[$fieldKey][] = ''; + } + } } ?> @@ -639,14 +696,11 @@ HTML; @php $fieldKey = $field['keyname'] ?? $field['key'] ?? $field['name']; $rawValue = $configuration[$fieldKey] ?? ($field['default'] ?? ''); - # These are sanitized at PluginImportService when imported, safe to render HTML + + # These are sanitized at Model/Plugin level, safe to render HTML $safeDescription = $field['description'] ?? ''; $safeHelp = $field['help_text'] ?? ''; - //Important: Sanitize with Purify to prevent XSS attacks - // $safeDescription = Stevebauman\Purify\Facades\Purify::clean($field['description'] ?? ''); - // $safeHelp = Stevebauman\Purify\Facades\Purify::clean($field['help_text'] ?? ''); - // For code fields, if the value is an array, JSON encode it if ($field['field_type'] === 'code' && is_array($rawValue)) { $currentValue = json_encode($rawValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); @@ -908,17 +962,60 @@ HTML; @endif - @elseif($field['field_type'] === 'multi_string') + @elseif($field['field_type'] === 'multi_string') + + {{ $field['name'] }} + {!! $safeDescription !!} + +
+ @foreach($multiValues[$fieldKey] as $index => $item) +
+ + + + @if(count($multiValues[$fieldKey]) > 1) + + @endif +
+ @endforeach + + + Add Item + +
+ + + {!! $safeHelp !!} +
+ {{-- @elseif($field['field_type'] === 'multi_string') {{ $field['name'] }} {!! $safeDescription !!} - - {!! $safeHelp !!} - + /> --}} + + {{-- {!! $safeHelp !!} + --}} @else Field type "{{ $field['field_type'] }}" not yet supported @endif