diff --git a/src/Fieldtypes/Terms.php b/src/Fieldtypes/Terms.php index 0b75a98421..6bb20c0ea4 100644 --- a/src/Fieldtypes/Terms.php +++ b/src/Fieldtypes/Terms.php @@ -184,7 +184,9 @@ public function process($data) } return explode('::', $id, 2)[1]; - })->all(); + }) + ->unique() + ->all(); if ($this->field->get('max_items') === 1) { return $data[0] ?? null; @@ -410,12 +412,16 @@ protected function createTermFromString($string, $taxonomy) ? Site::get($parent->locale())->lang() : Site::default()->lang(); - $term = Facades\Term::make() - ->slug(Str::slug($string, '-', $lang)) - ->taxonomy(Facades\Taxonomy::findByHandle($taxonomy)) - ->set('title', $string); + $slug = Str::slug($string, '-', $lang); + + if (! $term = Facades\Term::find("{$taxonomy}::{$slug}")) { + $term = Facades\Term::make() + ->slug($slug) + ->taxonomy(Facades\Taxonomy::findByHandle($taxonomy)) + ->set('title', $string); - $term->save(); + $term->save(); + } return $term->id(); }