Skip to content

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

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

Merged
merged 8 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Entries/UpdateStructuredEntryChildUris.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Statamic\Entries;

use Statamic\Events\EntrySaved;

class UpdateStructuredEntryChildUris
{
public function handle(EntrySaved $event)
{
$entry = $event->entry;
$collection = $entry->collection();

// If it's orderable (single depth structure) then changing the
// position of the entries is never going to affect the uris.
if ($collection->orderable()) {
return;
}

// If the collection has no route, there are no uris to update.
if (! $collection->route($entry->locale())) {
return;
}

// If there's no page, there are no children to update.
if (! $page = $entry->page()) {
return;
}

$ids = $page->flattenedPages()->pluck('id');

if (empty($ids)) {
return;
}

$collection->updateEntryUris($ids);
}
}
3 changes: 3 additions & 0 deletions src/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class EventServiceProvider extends ServiceProvider
\Statamic\Entries\UpdateStructuredEntryUris::class,
\Statamic\Entries\UpdateStructuredEntryOrder::class,
],
\Statamic\Events\EntrySaved::class => [
\Statamic\Entries\UpdateStructuredEntryChildUris::class,
],
\Statamic\Events\EntryBlueprintFound::class => [
\Statamic\Entries\AddSiteColumnToBlueprint::class,
],
Expand Down