Skip to content

Commit ea374e8

Browse files
committed
Pass along the parent
1 parent 85f9fd9 commit ea374e8

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

src/Entries/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function entryBlueprint($blueprint = null, $entry = null)
214214
$blueprint = $blueprint ? $this->ensureEntryBlueprintFields($blueprint) : null;
215215

216216
if ($blueprint) {
217-
EntryBlueprintFound::dispatch($blueprint, $entry);
217+
EntryBlueprintFound::dispatch($blueprint->setParent($entry), $entry);
218218
}
219219

220220
return $blueprint;

src/Fields/Blueprint.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Blueprint implements Augmentable
2727
protected $initialPath;
2828
protected $contents;
2929
protected $fieldsCache;
30+
protected $parent;
3031
protected $ensuredFields = [];
3132

3233
public function setHandle(string $handle)
@@ -227,6 +228,13 @@ public function fileData()
227228
return $this->contents();
228229
}
229230

231+
public function setParent($parent)
232+
{
233+
$this->parent = $parent;
234+
235+
return $this;
236+
}
237+
230238
public function sections(): Collection
231239
{
232240
return collect(Arr::get($this->contents(), 'sections', []))->map(function ($contents, $handle) {
@@ -242,7 +250,7 @@ public function fields(): Fields
242250

243251
$this->validateUniqueHandles();
244252

245-
$fields = new Fields($this->sections()->map->fields()->flatMap->items());
253+
$fields = new Fields($this->sections()->map->fields()->flatMap->items(), $this->parent);
246254

247255
$this->fieldsCache = $fields;
248256

src/Fields/Field.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public function __construct($handle, array $config)
2121

2222
public function newInstance()
2323
{
24-
return (new static($this->handle, $this->config))->setValue($this->value);
24+
return (new static($this->handle, $this->config))
25+
->setParent($this->parent)
26+
->setValue($this->value);
2527
}
2628

2729
public function setHandle(string $handle)

src/Fields/Fields.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ class Fields
1111
{
1212
protected $items;
1313
protected $fields;
14+
protected $parent;
1415

15-
public function __construct($items = [])
16+
public function __construct($items = [], $parent = null)
1617
{
17-
$this->setItems($items);
18+
$this
19+
->setParent($parent)
20+
->setItems($items);
1821
}
1922

2023
public function setItems($items)
@@ -39,6 +42,13 @@ public function setFields($fields)
3942
return $this;
4043
}
4144

45+
public function setParent($parent)
46+
{
47+
$this->parent = $parent;
48+
49+
return $this;
50+
}
51+
4252
public function items()
4353
{
4454
return $this->items;
@@ -62,6 +72,7 @@ public function only(...$keys): self
6272
public function newInstance()
6373
{
6474
return (new static)
75+
->setParent($this->parent)
6576
->setItems($this->items)
6677
->setFields($this->fields);
6778
}
@@ -168,7 +179,7 @@ private function createField(array $config)
168179

169180
protected function newField($handle, $config)
170181
{
171-
return new Field($handle, $config);
182+
return (new Field($handle, $config))->setParent($this->parent);
172183
}
173184

174185
private function getReferencedField(array $config): Field

0 commit comments

Comments
 (0)