Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Update child URIs when parent slug changes #9454

Merged
merged 8 commits into from May 8, 2024
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