Skip to content

Commit

Permalink
[4.x] Prevent ensuring fields on entries if they already exist (#8926)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Nov 6, 2023
1 parent 259f7ae commit 176d716
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Entries/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
Expand All @@ -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()],
Expand Down

0 comments on commit 176d716

Please sign in to comment.