diff --git a/src/Fieldtypes/ImportMappingsFieldtype.php b/src/Fieldtypes/ImportMappingsFieldtype.php index 71681b5..d396621 100644 --- a/src/Fieldtypes/ImportMappingsFieldtype.php +++ b/src/Fieldtypes/ImportMappingsFieldtype.php @@ -69,7 +69,6 @@ public function extraRules(): array return collect($this->field->value()) ->reject(fn ($row) => empty($row['key'])) - ->filter(fn ($row) => $fields->has($row['key'])) ->flatMap(function (array $row, string $field) use ($fields) { $rules = $fields ->get($field) diff --git a/src/Imports/Blueprint.php b/src/Imports/Blueprint.php index 4459518..57aee79 100644 --- a/src/Imports/Blueprint.php +++ b/src/Imports/Blueprint.php @@ -211,7 +211,7 @@ function (string $attribute, mixed $value, Closure $fail) { 'type' => 'radio', 'display' => __('Unique Field'), 'instructions' => __('importer::messages.unique_field_instructions'), - 'options' => $import?->mappingFields()->all() + 'options' => $import?->destinationBlueprint()->fields()->all() ->filter(fn ($field) => in_array($field->type(), ['text', 'integer', 'slug'])) ->map(fn ($field) => ['key' => $field->handle(), 'value' => $field->display()]) ->values(), diff --git a/tests/Imports/UpdateImportTest.php b/tests/Imports/UpdateImportTest.php index 1741d9f..c0e8375 100644 --- a/tests/Imports/UpdateImportTest.php +++ b/tests/Imports/UpdateImportTest.php @@ -5,6 +5,7 @@ use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; use PHPUnit\Framework\Attributes\Test; +use Statamic\Facades\Blink; use Statamic\Facades\Collection; use Statamic\Facades\Taxonomy; use Statamic\Facades\User; @@ -229,9 +230,19 @@ public function validation_error_is_thrown_for_terms_import_without_slug_mapping { Taxonomy::make('tags')->save(); + Storage::disk('local')->put('statamic/imports/tags/tags.csv', ''); + + $import = Import::make()->name('Users')->config([ + 'type' => 'csv', + 'path' => Storage::disk('local')->path('statamic/imports/tags/tags.csv'), + 'destination' => ['type' => 'terms', 'taxonomy' => 'tags', 'blueprint' => 'tag'], + ]); + + $import->save(); + $this ->actingAs(User::make()->makeSuper()->save()) - ->patch("/cp/utilities/importer/{$this->import->id()}", [ + ->patch("/cp/utilities/importer/{$import->id()}", [ 'name' => 'Posts', 'file' => ['posts.csv'], 'destination' => ['type' => 'terms', 'taxonomy' => ['tags'], 'blueprint' => 'tag'], @@ -258,9 +269,19 @@ public function validation_error_is_thrown_for_users_import_without_email_mappin ], ]); + Storage::disk('local')->put('statamic/imports/users/users.csv', ''); + + $import = Import::make()->name('Users')->config([ + 'type' => 'csv', + 'path' => Storage::disk('local')->path('statamic/imports/users/users.csv'), + 'destination' => ['type' => 'users'], + ]); + + $import->save(); + $this ->actingAs(User::make()->makeSuper()->save()) - ->patch("/cp/utilities/importer/{$this->import->id()}", [ + ->patch("/cp/utilities/importer/{$import->id()}", [ 'name' => 'Posts', 'file' => ['posts.csv'], 'destination' => ['type' => 'users'],