Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fixed a bug where legacy plugin-defined `actions.php` routes could collide between plugins. ([#18994](https://github.com/craftcms/cms/pull/18994))
- Fixed a bug where JavaScript and CSS registered by utility pages weren’t executed when navigating between utility
pages, and weren’t cleaned up when navigating away. ([#18978](https://github.com/craftcms/cms/issues/18978))
- Fixed a bug where custom element authorization methods weren’t respected by Laravel element policies. ([#18983](https://github.com/craftcms/cms/pull/18983))
Expand Down
8 changes: 7 additions & 1 deletion src/Plugin/Concerns/HasRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,23 @@ protected function registerCpRoutes(string|Closure $routes): void

protected function registerActionRoutes(string|Closure $routes): void
{
$handle = self::getInstance()->handle;

$this->app['router']
->middleware(['web', 'craft', 'craft.cp'])
->prefix(implode('/', [
Cms::config()->cpTrigger,
Cms::config()->actionTrigger,
$handle,
]))
->group($routes);

$this->app['router']
->middleware(['craft', 'craft.web'])
->prefix(Cms::config()->actionTrigger)
->prefix(implode('/', [
Cms::config()->actionTrigger,
$handle,
]))
->group($routes);
}
}
8 changes: 5 additions & 3 deletions tests/Unit/Plugin/Concerns/HasRoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@

expect($uris)->toContain('plugin-web')
->and($uris)->toContain('admin/plugin-cp')
->and($uris)->toContain('admin/actions/plugin-action')
->and($uris)->toContain('actions/plugin-action');
->and($uris)->toContain('admin/actions/test-plugin/plugin-action')
->and($uris)->toContain('actions/test-plugin/plugin-action')
->and($uris)->not()->toContain('admin/actions/plugin-action')
->and($uris)->not()->toContain('actions/plugin-action');

$routesByUri = collect(Route::getRoutes()->getRoutes())
->keyBy(fn ($route) => $route->uri());

expect($routesByUri->get('admin/plugin-cp')->middleware())->toContain('web', 'craft', 'craft.cp')
->and($routesByUri->get('admin/actions/plugin-action')->middleware())->toContain('web', 'craft', 'craft.cp');
->and($routesByUri->get('admin/actions/test-plugin/plugin-action')->middleware())->toContain('web', 'craft', 'craft.cp');
});
Loading