Adds ExtendableDashboard attribute to fix route name duplication when extending a DashboardController #6735
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Attribute
#[ExtendableDashboard]
can be added to any DashboardController. It has one optional argument,#[ExtendableDashboard(hasExtraRoutes: <bool>)]
.This attribute aims to fix an issue with route generation when using pretty urls and extended Dashboard Controllers with custom routes. When a controller extends an existing dashboard controller, AdminRouteGenerator tries to duplicate all of the routes, but fails due to duplicate route names.
If the ExtendableDashboard attribute is added to the base dashboard controller, AdminRouteGenerator will find all controllers which are a subclass of the base controller. Then, if hasExtraRoutes is false (default), the AdminRouteGenerator will skip routing entirely for the controller (because it will be / has already been done). If hasExtraRoutes is true, the AdminRouteGenerator will run on the controller like normal but will simply skip over any duplicate routes instead of throwing an error.
I'm not very familiar with the code base, so I fully expect this to be the wrong way to fix the issue, but at the very least this serves as a proof of concept to fix route generation for Controllers extended from DashboardControllers.
To replicate the issue, make a new Controller that extends a DashboardController and create a new function with a route. Clear cache and you will receive an error "all CRUD controllers must have unique PHP class names to generate unique route names". Add the attribute with
hasExtraRoutes: true
to at least the base dashboard controller, clear cache again, and all routes should work fine.