Skip to content

Commit 402feb2

Browse files
committed
Prevent error when there's a set without any fields ...
There's no way to send "an empty object" from PHP to JS. An empty array in PHP becomes an empty object in JS. So, setting this stupid underscore key to force it to be an object.
1 parent a5fd579 commit 402feb2

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

resources/js/components/fieldtypes/replicator/ManagesPreviewText.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default {
33
computed: {
44
previewText() {
55
const previews = _(this.previews).filter((value, handle) => {
6-
const config = _.findWhere(this.config.fields, { handle });
6+
const config = _.findWhere(this.config.fields, { handle }) || {};
77
return config.replicator_preview === undefined ? true : config.replicator_preview;
88
});
99

src/Fieldtypes/Bard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,15 @@ public function preload()
313313
$values = $set['attrs']['values'];
314314
$config = $this->config("sets.{$values['type']}.fields", []);
315315

316-
return [$set['attrs']['id'] => (new Fields($config))->addValues($values)->meta()];
316+
return [$set['attrs']['id'] => (new Fields($config))->addValues($values)->meta()->put('_', '_')];
317317
})->toArray();
318318

319319
$defaults = collect($this->config('sets'))->map(function ($set) {
320320
return (new Fields($set['fields']))->all()->map->defaultValue()->all();
321321
})->all();
322322

323323
$new = collect($this->config('sets'))->map(function ($set, $handle) use ($defaults) {
324-
return (new Fields($set['fields']))->addValues($defaults[$handle])->meta();
324+
return (new Fields($set['fields']))->addValues($defaults[$handle])->meta()->put('_', '_');
325325
})->toArray();
326326

327327
$previews = collect($existing)->map(function ($fields) {

src/Fieldtypes/Replicator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ public function preload()
136136
'existing' => $existing = collect($this->field->value())->mapWithKeys(function ($set) {
137137
$config = $this->config("sets.{$set['type']}.fields", []);
138138

139-
return [$set['_id'] => (new Fields($config))->addValues($set)->meta()];
139+
return [$set['_id'] => (new Fields($config))->addValues($set)->meta()->put('_', '_')];
140140
})->toArray(),
141141
'new' => collect($this->config('sets'))->map(function ($set, $handle) {
142-
return (new Fields($set['fields']))->meta();
142+
return (new Fields($set['fields']))->meta()->put('_', '_');
143143
})->toArray(),
144144
'defaults' => collect($this->config('sets'))->map(function ($set) {
145145
return (new Fields($set['fields']))->all()->map->defaultValue();

0 commit comments

Comments
 (0)