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

#39 shouldRegisterSpotlight() for resources and resource pages #40

Merged
merged 5 commits into from
Feb 22, 2024
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
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ CMD + /

This plugin relies on the same properties and methods used for Filament's global search. For records showing up with the correct name in "Edit/View" you need to set `$recordTitleAttribute`. [Check the docs for more information](https://filamentphp.com/docs/2.x/admin/resources/global-search)

#### Excluding pages

If you need to exclude a page from the spotlight results you may do so by adding a static `shouldRegisterSpotlight` method to the page and return false:

```php
public static function shouldRegisterSpotlight(): bool
{
return false;
}
```

This can be useful when you have pages that require URL parameters.

## Translation

To translate or edit the default placeholder, you have to publish the translation file for *wire-element/spotlight*:
Expand Down
4 changes: 4 additions & 0 deletions src/Actions/RegisterPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public static function boot(Panel $panel)
*/
$page = new $pageClass();

if (method_exists($page, 'shouldRegisterSpotlight') && $page::shouldRegisterSpotlight() === false) {
continue;
}

$name = collect([
$page->getNavigationGroup(),
$page->getTitle(),
Expand Down
8 changes: 8 additions & 0 deletions src/Actions/RegisterResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ public static function boot(Panel $panel)
$resources = $panel->getResources();

foreach ($resources as $resource) {
if (method_exists($resource, 'shouldRegisterSpotlight') && $resource::shouldRegisterSpotlight() === false) {
continue;
}

$pages = $resource::getPages();

foreach ($pages as $key => $page) {
if (method_exists($page->getPage(), 'shouldRegisterSpotlight') && $page->getPage()::shouldRegisterSpotlight() === false) {
continue;
}

/**
* @var PageRegistration $page
*/
Expand Down