33namespace Aerni \Factory \Factories \Concerns ;
44
55use Illuminate \Support \Arr ;
6+ use Statamic \Fields \Blueprint ;
67use Statamic \Contracts \Taxonomies \Term ;
78use Statamic \Facades \Term as TermFacade ;
9+ use Statamic \Facades \Blueprint as BlueprintFacade ;
810
911trait CreatesTerm
1012{
@@ -16,8 +18,8 @@ trait CreatesTerm
1618 public function newModel (array $ attributes = []): Term
1719 {
1820 $ term = TermFacade::make ()
19- ->taxonomy ($ this ->taxonomy ())
20- ->blueprint ($ this ->blueprint ());
21+ ->taxonomy ($ this ->taxonomyHandle ())
22+ ->blueprint ($ this ->blueprintHandle ());
2123
2224 $ published = Arr::pull ($ attributes , 'published ' , true );
2325 $ slug = Arr::pull ($ attributes , 'slug ' );
@@ -47,7 +49,7 @@ public function newModel(array $attributes = []): Term
4749 return $ term ;
4850 }
4951
50- protected function taxonomy (): string
52+ protected function taxonomyHandle (): string
5153 {
5254 return $ this ->taxonomy
5355 ?? str (get_class ($ this ))
@@ -56,7 +58,7 @@ protected function taxonomy(): string
5658 ->lower ();
5759 }
5860
59- protected function blueprint (): string
61+ protected function blueprintHandle (): string
6062 {
6163 return $ this ->blueprint
6264 ?? str (get_class ($ this ))
@@ -65,8 +67,13 @@ protected function blueprint(): string
6567 ->lower ();
6668 }
6769
70+ protected function blueprint (): Blueprint
71+ {
72+ return BlueprintFacade::find ("taxonomies/ {$ this ->taxonomyHandle ()}/ {$ this ->blueprintHandle ()}" );
73+ }
74+
6875 public function modelName (): string
6976 {
70- return parent ::modelName ().'\\' .ucfirst ($ this ->collection ()).'\\' .ucfirst ($ this ->blueprint ());
77+ return parent ::modelName ().'\\' .ucfirst ($ this ->taxonomyHandle ()).'\\' .ucfirst ($ this ->blueprintHandle ());
7178 }
7279}
0 commit comments