Skip to content

Commit b3b4a17

Browse files
Duncan McCleanjasonvarga
andauthored
Add 'mount' variable to Entries (#3046)
Co-authored-by: Jason Varga <jason@pixelfear.com>
1 parent 45c2731 commit b3b4a17

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Entries/AugmentedEntry.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Statamic\Entries;
44

55
use Statamic\Data\AbstractAugmented;
6+
use Statamic\Facades\Collection;
67

78
class AugmentedEntry extends AbstractAugmented
89
{
@@ -32,6 +33,7 @@ private function commonKeys()
3233
'order',
3334
'is_entry',
3435
'collection',
36+
'mount',
3537
'last_modified',
3638
'updated_at',
3739
'updated_by',
@@ -62,4 +64,9 @@ protected function parent()
6264
{
6365
return $this->data->parent();
6466
}
67+
68+
protected function mount()
69+
{
70+
return $this->data->value('mount') ?? Collection::findByMount($this->data);
71+
}
6572
}

tests/Data/Entries/AugmentedEntryTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public function it_gets_values()
7676
->setSupplement('three', 'the "three" value supplemented on the entry')
7777
->setSupplement('four', 'the "four" value supplemented on the entry and in the blueprint');
7878

79+
$mount = tap(Collection::make('mountable')->mount($entry->id()))->save();
80+
7981
$augmented = new AugmentedEntry($entry);
8082

8183
$expectations = [
@@ -93,6 +95,7 @@ public function it_gets_values()
9395
'order' => ['type' => 'null', 'value' => null], // todo: test for when this is an int
9496
'is_entry' => ['type' => 'bool', 'value' => true],
9597
'collection' => ['type' => CollectionContract::class, 'value' => $collection],
98+
'mount' => ['type' => CollectionContract::class, 'value' => $mount],
9699
'last_modified' => ['type' => Carbon::class, 'value' => '2017-02-03 14:10'],
97100
'updated_at' => ['type' => Carbon::class, 'value' => '2017-02-03 14:10'],
98101
'updated_by' => ['type' => UserContract::class, 'value' => 'test-user'],
@@ -109,4 +112,25 @@ public function it_gets_values()
109112

110113
$this->assertAugmentedCorrectly($expectations, $augmented);
111114
}
115+
116+
/** @test */
117+
public function it_gets_the_mount_from_the_value_first_if_it_exists()
118+
{
119+
$mount = tap(Collection::make('a'))->save();
120+
121+
$entry = EntryFactory::id('entry-id')
122+
->collection('test')
123+
->slug('entry-slug')
124+
->create();
125+
126+
$augmented = new AugmentedEntry($entry);
127+
128+
$this->assertNull($augmented->get('mount'));
129+
130+
$mount->mount($entry->id())->save();
131+
$this->assertEquals($mount, $augmented->get('mount'));
132+
133+
$entry->set('mount', 'b');
134+
$this->assertEquals('b', $augmented->get('mount'));
135+
}
112136
}

0 commit comments

Comments
 (0)