Skip to content

Commit

Permalink
Show "Site" dropdown when configuring taxonomy import
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Dec 19, 2024
1 parent 9e512d0 commit 9350434
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'file_type_not_allowed' => 'Only CSV and XML files can be imported at this time.',
'mappings_not_provided' => 'You must map at least one field.',
'site_not_configured_in_collection' => 'The chosen collection is not available on this site.',
'site_not_configured_in_taxonomy' => 'The chosen taxonomy is not available on this site.',
'unique_field_without_mapping' => 'Please configure a mapping for this field.',
'uploaded_file_not_found' => 'The uploaded file could not be found.',
];
22 changes: 17 additions & 5 deletions src/Imports/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,26 @@ function (string $attribute, mixed $value, Closure $fail) use ($import) {
'width' => 50,
'max_items' => 1,
'mode' => 'select',
'if' => ['type' => 'entries'],
'unless' => ['type' => 'users'],
'validate' => [
'required_if:destination.type,entries',
'required_unless:destination.type,users',
function (string $attribute, mixed $value, Closure $fail) {
$collection = Collection::find(Arr::get(request()->destination, 'collection.0'));
$type = Arr::get(request()->destination, 'type');

if ($type === 'entries') {
$collection = Collection::find(Arr::get(request()->destination, 'collection.0'));

if (count($value) && ! $collection->sites()->contains($value[0])) {
$fail('importer::validation.site_not_configured_in_collection')->translate();
}
}

if ($type === 'terms') {
$taxonomy = Facades\Taxonomy::findByHandle(Arr::get(request()->destination, 'taxonomy.0'));

if (count($value) && ! $collection->sites()->contains($value[0])) {
$fail('importer::validation.site_not_configured_in_collection')->translate();
if (count($value) && ! $taxonomy->sites()->contains($value[0])) {
$fail('importer::validation.site_not_configured_in_taxonomy')->translate();
}
}
},
],
Expand Down

0 comments on commit 9350434

Please sign in to comment.