From 176d7167f018d076c150a574579b377c92fd210e Mon Sep 17 00:00:00 2001 From: Duncan McClean <19637309+duncanmcclean@users.noreply.github.com> Date: Mon, 6 Nov 2023 20:49:24 +0000 Subject: [PATCH] [4.x] Prevent ensuring fields on entries if they already exist (#8926) --- src/Entries/Collection.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index e5cdb3d688..ccff5aafd4 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -336,20 +336,22 @@ public function fallbackEntryBlueprint() public function ensureEntryBlueprintFields($blueprint) { - $blueprint->ensureFieldPrepended('title', [ - 'type' => ($auto = $this->autoGeneratesTitles()) ? 'hidden' : 'text', - 'required' => ! $auto, - ]); + if (! $blueprint->hasField('title')) { + $blueprint->ensureFieldPrepended('title', [ + 'type' => ($auto = $this->autoGeneratesTitles()) ? 'hidden' : 'text', + 'required' => ! $auto, + ]); + } - if ($this->requiresSlugs()) { + if ($this->requiresSlugs() && ! $blueprint->hasField('slug')) { $blueprint->ensureField('slug', ['type' => 'slug', 'localizable' => true], 'sidebar'); } - if ($this->dated()) { + if ($this->dated() && ! $blueprint->hasField('date')) { $blueprint->ensureField('date', ['type' => 'date', 'required' => true, 'default' => 'now'], 'sidebar'); } - if ($this->hasStructure() && ! $this->orderable()) { + if ($this->hasStructure() && ! $this->orderable() && ! $blueprint->hasField('parent')) { $blueprint->ensureField('parent', [ 'type' => 'entries', 'collections' => [$this->handle()], @@ -360,6 +362,10 @@ public function ensureEntryBlueprintFields($blueprint) } foreach ($this->taxonomies() as $taxonomy) { + if ($blueprint->hasField($taxonomy->handle())) { + continue; + } + $blueprint->ensureField($taxonomy->handle(), [ 'type' => 'terms', 'taxonomies' => [$taxonomy->handle()],