diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index 8c89afe4be..3cb3c86d6e 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -10,6 +10,7 @@ use Statamic\Data\ContainsCascadingData; use Statamic\Data\ExistsAsFile; use Statamic\Data\HasAugmentedData; +use Statamic\Data\HasDirtyState; use Statamic\Events\CollectionCreated; use Statamic\Events\CollectionCreating; use Statamic\Events\CollectionDeleted; @@ -34,7 +35,7 @@ class Collection implements Arrayable, ArrayAccess, AugmentableContract, Contract { - use ContainsCascadingData, ExistsAsFile, FluentlyGetsAndSets, HasAugmentedData; + use ContainsCascadingData, ExistsAsFile, FluentlyGetsAndSets, HasAugmentedData, HasDirtyState; protected $handle; protected $routes = []; @@ -486,6 +487,10 @@ public function save() Facades\Collection::save($this); + if ($this->isDirty('route')) { + Facades\Entry::updateUris($this); + } + Blink::forget('collection-handles'); Blink::forget('mounted-collections'); Blink::flushStartingWith("collection-{$this->id()}"); @@ -498,6 +503,8 @@ public function save() CollectionSaved::dispatch($this); } + $this->syncOriginal(); + return $this; } @@ -928,4 +935,9 @@ public function augmentedArrayData() 'handle' => $this->handle(), ]; } + + public function getCurrentDirtyStateAttributes(): array + { + return $this->fileData(); + } } diff --git a/tests/Data/Entries/CollectionTest.php b/tests/Data/Entries/CollectionTest.php index a751ec419f..7f1a01943d 100644 --- a/tests/Data/Entries/CollectionTest.php +++ b/tests/Data/Entries/CollectionTest.php @@ -504,6 +504,7 @@ public function it_saves_the_collection_through_the_api() Facades\Blink::shouldReceive('forget')->with('collection-handles')->once(); Facades\Blink::shouldReceive('forget')->with('mounted-collections')->once(); Facades\Blink::shouldReceive('flushStartingWith')->with('collection-test')->once(); + Facades\Blink::shouldReceive('once')->with('collection-test-structure', \Mockery::any())->andReturnNull(); $return = $collection->save();