@props([ 'fields' => [], 'currentLocaleCode' => core()->getRequestedLocaleCode(), 'fieldsWrapper' => 'additional_data', 'fieldValues' => [], ]) @foreach($fields as $field) @php $isLocalizable = (bool) $field->value_per_locale; $value = ''; $formattedoptions = []; $fieldName = $isLocalizable ? $fieldsWrapper . "[locale_specific]" . '[' . $currentLocaleCode . ']' . '[' . $field->code . ']' : $fieldsWrapper . '[common]' . '[' . $field->code . ']'; $flatFieldName = $isLocalizable ? $fieldsWrapper . ".locale_specific." . $currentLocaleCode . '.' . $field->code : $fieldsWrapper . '.common.' . $field->code; if ($fieldValues) { $value = $isLocalizable ? ($fieldValues['locale_specific'][$currentLocaleCode][$field->code] ?? '') : ($fieldValues['common'][$field->code] ?? ''); } $value = old($flatFieldName) ?? $value; $fieldLabel = $field->translate($currentLocaleCode)['name'] ?? ''; $fieldLabel = empty($fieldLabel) ? '['.$field->code.']' : $fieldLabel; $fieldType = $field->type; @endphp {!! view_render_event('unopim.admin.categories.dynamic-fields.field.before', ['field' => $field]) !!}
{{ $fieldLabel }} @if ($field->is_required) @endif
@if ($isLocalizable) {{ "{$currentLocaleCode}" }} @endif
{!! view_render_event('unopim.admin.categories.dynamic-fields.control.'.$fieldType.'.before', ['field' => $field, 'value' => $value, 'fieldName' => $fieldName]) !!} @switch ($fieldType) @case ('checkbox') @if (! empty($value)) @endIf @php $fieldName = $fieldName.'[]'; $selectedValue = ! empty($value) ? explode(',', $value) : $value; $selectedValue = empty($selectedValue) ? [] : $selectedValue; @endphp @foreach ($field->options as $option)
@endforeach @break @case ('boolean') @break @case('image') @php $savedImage = ! empty($value) ? [ 'id' => 0, 'url' => Storage::url($value), 'value' => $value, ] : []; @endphp @if (! empty($value)) @endIf @break @case('file') @php $fileName = last(explode('/', $value)); $fileName = strlen($fileName) > 20 ? substr($fileName, 0, 20) . '...' : $fileName; $savedFile = ! empty($value) ? [ 'id' => 0, 'url' => Storage::url($value), 'value' => $value, 'fileName' => $fileName, ] : []; @endphp @if (! empty($value)) @endIf @break @case('multiselect') @php $value = str_contains($value, ',') ? explode(',', $value) : (empty($value) ? '' : [$value]); @endphp @case('select') @php $selectedValue = []; foreach ($field->options->whereIn('code', $value) as $option) { $translatedOptionLabel = $option->translate($currentLocaleCode)?->label; $selectedValue[] = [ 'id' => $option->id, 'code' => $option->code, 'label' => ! empty($translatedOptionLabel) ? $translatedOptionLabel : "[{$option->code}]", ]; } if ('select' == $fieldType) { $selectedValue = ! empty($selectedValue[0]) ? $selectedValue[0] : $selectedValue; } $value = ! empty($selectedValue) ? json_encode($selectedValue) : ''; @endphp @default @endswitch @if ($field->is_unique) @endIf {!! view_render_event('unopim.admin.categories.dynamic-fields.control.'.$fieldType.'.after', ['field' => $field, 'value' => $value, 'fieldName' => $fieldName]) !!}
{!! view_render_event('unopim.admin.categories.dynamic-fields.field.after', ['fieldType' => $fieldType]) !!} @endforeach