feat: allow the host app to register its own management page - #200
Merged
Conversation
Filament reads sub-navigation, breadcrumbs and header actions off the page class, none of which the `management` config block can reach. Consumers that want the custom fields screen inside their own settings navigation had no option but to subclass and live with the packaged page still registered on the panel — a second, unlinked route to the same screen. `CustomFieldsPlugin::managementPage()` swaps the registered page instead of adding to it, so there is exactly one route either way. The class must extend `CustomFieldsManagementPage`, so all packaged behaviour is inherited by default.
is_subclass_of() is false for the class itself, so passing CustomFieldsManagementPage::class — a legitimate explicit 'use the default' — threw. is_a(..., allow_string: true) accepts the class and its subclasses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The
managementconfig block covers slug, navigation sort/group and cluster. But Filament reads several things off the page class itself —getSubNavigation(), breadcrumbs, header actions — and config cannot reach any of them.A consumer that wants the custom fields screen inside its own settings navigation therefore has to subclass
CustomFieldsManagementPageand register the subclass on the panel.CustomFieldsPlugin::register()still adds the packaged page unconditionally, andPanel::getPages()de-duplicates by class string only — so the app ends up with two routes to the same screen, one of them unlinked.The
clusteroption is not a way out:Page::getRoutePath()applies the cluster slug as a route prefix, so it moves the URL as a side effect of wanting navigation.Solution
CustomFieldsPlugin::managementPage()— swaps the registered page rather than adding to it, so there is exactly one route either way.The class must extend
CustomFieldsManagementPage(guarded with anInvalidArgumentException), so every packaged behaviour is inherited by default and a consumer overrides only what it needs. Default behaviour is unchanged when the option is not used.Testing
tests/Feature/ManagementPageOverrideTest.phpcovers the default, the override, the subclass guard, and thatregister()puts only the override on the panel. I verified that last one is load-bearing by revertingregister()to the hardcoded class — it fails.Pre-existing on
3.x, not touched here:composer test:type-coveragereports 99.4% (below the 100% gate) and Rector flagstests/Feature/ConsumerScopeHooksTest.php:469. Both reproduce with my changes stashed.