Skip to content

Commit

Permalink
Add 'mount' variable to Entries (#3046)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <jason@pixelfear.com>
  • Loading branch information
Duncan McClean and jasonvarga committed Dec 23, 2020
1 parent 45c2731 commit b3b4a17
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Entries/AugmentedEntry.php
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Entries;

use Statamic\Data\AbstractAugmented;
use Statamic\Facades\Collection;

class AugmentedEntry extends AbstractAugmented
{
Expand Down Expand Up @@ -32,6 +33,7 @@ private function commonKeys()
'order',
'is_entry',
'collection',
'mount',
'last_modified',
'updated_at',
'updated_by',
Expand Down Expand Up @@ -62,4 +64,9 @@ protected function parent()
{
return $this->data->parent();
}

protected function mount()
{
return $this->data->value('mount') ?? Collection::findByMount($this->data);
}
}
24 changes: 24 additions & 0 deletions tests/Data/Entries/AugmentedEntryTest.php
Expand Up @@ -76,6 +76,8 @@ public function it_gets_values()
->setSupplement('three', 'the "three" value supplemented on the entry')
->setSupplement('four', 'the "four" value supplemented on the entry and in the blueprint');

$mount = tap(Collection::make('mountable')->mount($entry->id()))->save();

$augmented = new AugmentedEntry($entry);

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

$this->assertAugmentedCorrectly($expectations, $augmented);
}

/** @test */
public function it_gets_the_mount_from_the_value_first_if_it_exists()
{
$mount = tap(Collection::make('a'))->save();

$entry = EntryFactory::id('entry-id')
->collection('test')
->slug('entry-slug')
->create();

$augmented = new AugmentedEntry($entry);

$this->assertNull($augmented->get('mount'));

$mount->mount($entry->id())->save();
$this->assertEquals($mount, $augmented->get('mount'));

$entry->set('mount', 'b');
$this->assertEquals('b', $augmented->get('mount'));
}
}

0 comments on commit b3b4a17

Please sign in to comment.