Skip to content

Commit

Permalink
Fix validation error when creating an import in a multi-site (#27)
Browse files Browse the repository at this point in the history
* Fix validation error when creating an import in a multi-site

* `destination_site` is an array
  • Loading branch information
duncanmcclean authored Nov 6, 2024
1 parent c90967a commit a771984
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Http/Controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function store(CreateImportRequest $request)
'type' => $request->destination_type,
'collection' => Arr::first($request->destination_collection),
'taxonomy' => Arr::first($request->destination_taxonomy),
'site' => $request->destination_site,
'site' => Arr::first($request->destination_site),
])->filter()->all(),
]);

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/CreateImportRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function rules(): array
'destination_site' => [
Rule::requiredIf(fn () => Site::hasMultiple() && $this->destination_type === 'entries'),
function (string $attribute, mixed $value, Closure $fail) {
if ($value && $this->destination_collection && ! Collection::find($this->destination_collection[0])->sites()->contains($value)) {
if (isset($value[0]) && $this->destination_collection && ! Collection::find($this->destination_collection[0])->sites()->contains($value[0])) {
$fail('The chosen collection is not available on this site.')->translate();
}
},
Expand Down
4 changes: 2 additions & 2 deletions tests/Imports/StoreImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function it_stores_a_collection_import_with_a_site()
],
'destination_type' => 'entries',
'destination_collection' => ['posts'],
'destination_site' => 'en',
'destination_site' => ['en'],
'strategy' => ['create', 'update'],
])
->assertJsonStructure(['redirect']);
Expand Down Expand Up @@ -114,7 +114,7 @@ public function it_cant_store_a_collection_import_when_the_collection_is_not_ava
],
'destination_type' => 'entries',
'destination_collection' => ['posts'],
'destination_site' => 'fr',
'destination_site' => ['fr'],
'strategy' => ['create', 'update'],
])
->assertSessionHasErrors('destination_site');
Expand Down

0 comments on commit a771984

Please sign in to comment.