diff --git a/routes/cp.php b/routes/cp.php index 3048c10f64f..19f87438260 100644 --- a/routes/cp.php +++ b/routes/cp.php @@ -28,6 +28,7 @@ use Statamic\Http\Controllers\CP\Collections\CollectionBlueprintsController; use Statamic\Http\Controllers\CP\Collections\CollectionsController; use Statamic\Http\Controllers\CP\Collections\CollectionTreeController; +use Statamic\Http\Controllers\CP\Collections\EditRedirectController; use Statamic\Http\Controllers\CP\Collections\EntriesController; use Statamic\Http\Controllers\CP\Collections\EntryActionController; use Statamic\Http\Controllers\CP\Collections\EntryPreviewController; @@ -361,5 +362,7 @@ Route::view('/playground', 'statamic::playground')->name('playground'); + Route::get('edit/{id}', EditRedirectController::class); + Route::get('{segments}', [CpController::class, 'pageNotFound'])->where('segments', '.*')->name('404'); }); diff --git a/src/Http/Controllers/CP/Collections/EditRedirectController.php b/src/Http/Controllers/CP/Collections/EditRedirectController.php new file mode 100644 index 00000000000..5e040ff5bf6 --- /dev/null +++ b/src/Http/Controllers/CP/Collections/EditRedirectController.php @@ -0,0 +1,20 @@ +id)) { + return redirect($data->editUrl()); + } + + throw new NotFoundHttpException; + } +} diff --git a/tests/CP/EditRedirectControllerTest.php b/tests/CP/EditRedirectControllerTest.php new file mode 100644 index 00000000000..f71b3a6d006 --- /dev/null +++ b/tests/CP/EditRedirectControllerTest.php @@ -0,0 +1,39 @@ +shouldReceive('editUrl')->once()->andReturn($targetUrl = '/somewhere'); + Data::shouldReceive('find')->with('123')->once()->andReturn($item); + + $this + ->actingAs(tap(User::make()->makeSuper())->save()) + ->get('/cp/edit/123') + ->assertRedirect($targetUrl); + } + + #[Test] + public function it_404s_if_id_doesnt_exist() + { + Data::shouldReceive('find')->with('123')->once()->andReturnNull(); + + $this + ->actingAs(tap(User::make()->makeSuper())->save()) + ->get('/cp/edit/123') + ->assertNotFound(); + } +}