Skip to content

Commit

Permalink
[4.x] Prevent existing term data being overwritten in terms fieldtype (
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Nov 28, 2023
1 parent 612ba32 commit f7d78a2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Fieldtypes/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit f7d78a2

Please sign in to comment.