diff --git a/src/Fieldtypes/Terms.php b/src/Fieldtypes/Terms.php index c7b46cf028d..3408672388c 100644 --- a/src/Fieldtypes/Terms.php +++ b/src/Fieldtypes/Terms.php @@ -220,8 +220,13 @@ public function process($data) $id = $this->createTermFromString($id, $taxonomy); } + if (! $id) { + return null; + } + return explode('::', $id, 2)[1]; }) + ->filter() ->unique() ->values() ->all(); @@ -485,9 +490,15 @@ protected function createTermFromString($string, $taxonomy) $slug = Str::slug($string, '-', $lang); if (! $term = Facades\Term::find("{$taxonomy}::{$slug}")) { + $taxonomy = Facades\Taxonomy::findByHandle($taxonomy); + + if (User::current()->cant('create', [TermContract::class, $taxonomy])) { + return null; + } + $term = Facades\Term::make() ->slug($slug) - ->taxonomy(Facades\Taxonomy::findByHandle($taxonomy)) + ->taxonomy($taxonomy) ->set('title', $string); $term->save();