Skip to content

Commit

Permalink
[4.x] Update child URIs when parent slug changes (#9454)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <jason@pixelfear.com>
  • Loading branch information
jacksleight and jasonvarga committed May 8, 2024
1 parent cd88092 commit f6e5757
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Entries/Entry.php
Expand Up @@ -390,6 +390,7 @@ public function save()

if ($this->isDirty('slug')) {
optional(Collection::findByMount($this))->updateEntryUris();
$this->updateChildPageUris();
}

foreach ($afterSaveCallbacks as $callback) {
Expand Down Expand Up @@ -419,6 +420,28 @@ public function save()
return true;
}

private function updateChildPageUris()
{
$collection = $this->collection();

// If it's orderable (single depth structure), there are no children to update.
// If the collection has no route, there are no uris to update.
// If there's no page, there are no children to update.
if (
$collection->orderable()
|| ! $this->route()
|| ! ($page = $this->page())
) {
return;
}

if (empty($ids = $page->flattenedPages()->pluck('id'))) {
return;
}

$collection->updateEntryUris($ids);
}

public function taxonomize()
{
Facades\Entry::taxonomize($this);
Expand Down

0 comments on commit f6e5757

Please sign in to comment.