diff --git a/src/Entries/Entry.php b/src/Entries/Entry.php index b1113005624..7ff4c5109b0 100644 --- a/src/Entries/Entry.php +++ b/src/Entries/Entry.php @@ -185,7 +185,7 @@ public function collection($collection = null) public function blueprint($blueprint = null) { - $key = "entry-{$this->id()}-blueprint"; + $key = 'entry-'.($this->id() ?? 'obj-'.spl_object_id($this)).'-blueprint'; return $this ->fluentlyGetOrSet('blueprint') diff --git a/tests/Data/Entries/EntryTest.php b/tests/Data/Entries/EntryTest.php index a87b106f23e..1b37cb24581 100644 --- a/tests/Data/Entries/EntryTest.php +++ b/tests/Data/Entries/EntryTest.php @@ -1358,6 +1358,25 @@ public function it_gets_the_default_collection_blueprint_when_undefined() $this->assertNotSame($first, $second); } + #[Test] + public function unsaved_entries_in_different_collections_do_not_share_a_blueprint() + { + BlueprintRepository::shouldReceive('in')->with('collections/blog')->andReturn(collect([ + 'post' => $post = (new Blueprint)->setHandle('post'), + ])); + BlueprintRepository::shouldReceive('in')->with('collections/products')->andReturn(collect([ + 'product' => $product = (new Blueprint)->setHandle('product'), + ])); + $blog = tap(Collection::make('blog'))->save(); + $products = tap(Collection::make('products'))->save(); + + $blogEntry = (new Entry)->collection($blog); + $productEntry = (new Entry)->collection($products); + + $this->assertSame($post, $blogEntry->blueprint()); + $this->assertSame($product, $productEntry->blueprint()); + } + #[Test] public function the_blueprint_is_blinked_when_getting_and_flushed_when_setting() { @@ -2154,6 +2173,7 @@ public function it_respects_custom_blueprint_template_path_per_collection() $blueprint = tap(Blueprint::make('standard_article')->setNamespace('collections.articles'))->save(); $articleEntry = Entry::make('test')->collection($articles)->blueprint($blueprint->handle()); + tap(Blueprint::make('standard_article')->setNamespace('collections.pages'))->save(); $pageEntry = Entry::make('test')->collection($pages)->blueprint($blueprint->handle()); // mapped collection uses the mapped prefix instead of the collection handle