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

Adds ExtendableDashboard attribute to fix route name duplication when extending a DashboardController #6735

Open
wants to merge 3 commits into
base: 4.x
Choose a base branch
from

Conversation

damonjones321
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant