Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions resources/js/components/fieldtypes/bard/BardFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,14 @@ export default {
const reference = this.publishContainer.reference;
const blueprint = this.publishContainer.blueprint.fqh;

if (this.meta.new?.hasOwnProperty(set)) {
let meta = this.meta.new[set];
let defaults = this.meta.defaults[set];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Duncan! Just wondering if this line would introduce similar effects of #13955 ?

Copy link
Member Author

@duncanmcclean duncanmcclean Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually already do a deep clone of the set's defaults here:

const deepCopy = JSON.parse(JSON.stringify(data.defaults));

The addSet() method calls fetchSet(), then once its got the set, it calls _addSet() which has the deep clone logic.


resolve({ new: meta, defaults });
return;
}

if (this.setsCache[setCacheKey]) {
resolve(this.setsCache[setCacheKey]);
return;
Expand Down
8 changes: 8 additions & 0 deletions resources/js/components/fieldtypes/replicator/Replicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ export default {
const reference = this.publishContainer.reference;
const blueprint = this.publishContainer.blueprint.fqh;

if (this.meta.new?.hasOwnProperty(set)) {
let meta = this.meta.new[set];
let defaults = this.meta.defaults[set];

resolve({ new: meta, defaults });
return;
}

if (this.setsCache[setCacheKey]) {
resolve(this.setsCache[setCacheKey]);
return;
Expand Down
25 changes: 25 additions & 0 deletions src/Fieldtypes/Bard.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,18 @@ public function preload()
return [$set['attrs']['id'] => $this->fields($values['type'], $index)->addValues($values)->meta()->put('_', '_')];
})->toArray();

if ($this->shouldProcessNewValues()) {
$defaults = collect($this->flattenedSetsConfig())->map(function ($set, $handle) {
return $this->fields($handle)->all()->map(function ($field) {
return $field->fieldtype()->preProcess($field->defaultValue());
})->all();
})->all();

$new = collect($this->flattenedSetsConfig())->map(function ($set, $handle) use ($defaults) {
return $this->fields($handle)->addValues($defaults[$handle])->meta()->put('_', '_');
})->toArray();
}

$previews = collect($existing)->map(function ($fields) {
return collect($fields)->map(function () {
return null;
Expand All @@ -637,6 +649,8 @@ public function preload()

$data = [
'existing' => $existing,
'new' => $new ?? null,
'defaults' => $defaults ?? null,
'collapsed' => $this->config('collapse') ? array_keys($existing) : [],
'previews' => $previews,
'__collaboration' => ['existing'],
Expand All @@ -663,6 +677,17 @@ public function preload()
return $this->runHooks('preload', $data);
}

private function shouldProcessNewValues(): bool
{
$parent = $this->field()->parent();

if (! $parent || ! method_exists($parent, 'blueprint')) {
return true;
}

return is_null($parent->blueprint()->fullyQualifiedHandle());
}

public function preProcessValidatable($value)
{
if (is_array($value)) {
Expand Down
33 changes: 33 additions & 0 deletions src/Fieldtypes/Replicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,45 @@ public function preload()
return [$set['_id'] => $this->fields($set['type'], $index)->addValues($set)->meta()->put('_', '_')];
})->toArray();

// Most of the time, these values will be fetched over AJAX.
// However, if the blueprint doesn't have a FQH, we need to fallback here.
if ($this->shouldProcessNewValues()) {
$blink = md5(json_encode($this->flattenedSetsConfig()));

$defaults = Blink::once($blink.'-defaults', function () {
return collect($this->flattenedSetsConfig())->map(function ($set, $handle) {
return $this->fields($handle)->all()->map(function ($field) {
return $field->fieldtype()->preProcess($field->defaultValue());
})->all();
})->all();
});

$new = Blink::once($blink.'-new', function () use ($defaults) {
return collect($this->flattenedSetsConfig())->map(function ($set, $handle) use ($defaults) {
return $this->fields($handle)->addValues($defaults[$handle])->meta()->put('_', '_');
})->toArray();
});
}

return [
'existing' => $existing,
'new' => $new ?? null,
'defaults' => $defaults ?? null,
'collapsed' => $this->config('collapse') ? array_keys($existing) : [],
];
}

private function shouldProcessNewValues(): bool
{
$parent = $this->field()->parent();

if (! $parent || ! method_exists($parent, 'blueprint')) {
return true;
}

return is_null($parent->blueprint()->fullyQualifiedHandle());
}

public function flattenedSetsConfig()
{
$blink = md5($this->field?->handle().json_encode($this->field?->config()));
Expand Down