From 289547c9de5bf1b0c72ba11d477196542380ed0a Mon Sep 17 00:00:00 2001 From: Abishek R Srikaanth <1639302+abishekrsrikaanth@users.noreply.github.com> Date: Mon, 27 May 2024 12:25:19 +0000 Subject: [PATCH 1/2] Render the plugin in a custom render hook --- README.md | 18 ++++++++++++++++++ src/QuickCreatePlugin.php | 11 ++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 75d2a4e..c8c9d2d 100644 --- a/README.md +++ b/README.md @@ -168,3 +168,21 @@ public function panel(Panel $panel): Panel ]) } ``` + +### Render Plugin on a Custom Panel Hook + +By default, Quick Create plugin renders using `'panels::user-menu.before'` Filament Panel Render Hook. If you would like to customize this to render at a different render hook, you may use the `renderUsingHook(string $panelHook)` modifier to do so. You may read about the available Render Hooks in Filament PHP [here](https://filamentphp.com/docs/3.x/support/render-hooks#available-render-hooks) + +```php +use Awcodes\FilamentQuickCreate\QuickCreatePlugin; +use Filament\View\PanelsRenderHook; + +public function panel(Panel $panel): Panel +{ + return $panel + ->plugins([ + QuickCreatePlugin::make() + ->renderUsingHook(PanelsRenderHook::SIDEBAR_NAV_END), + ]) +} +``` diff --git a/src/QuickCreatePlugin.php b/src/QuickCreatePlugin.php index e6b33ed..3c8135b 100644 --- a/src/QuickCreatePlugin.php +++ b/src/QuickCreatePlugin.php @@ -31,6 +31,8 @@ class QuickCreatePlugin implements Plugin protected bool | Closure | null $rounded = null; + protected string $renderUsingHook = 'panels::user-menu.before'; + public function boot(Panel $panel): void { Livewire::component('quick-create-menu', Components\QuickCreateMenu::class); @@ -146,7 +148,7 @@ public function register(Panel $panel): void { $panel ->renderHook( - name: 'panels::user-menu.before', + name: $this->renderUsingHook, hook: fn (): string => Blade::render('@livewire(\'quick-create-menu\')') ); } @@ -192,4 +194,11 @@ public function shouldBeHidden(): bool { return $this->evaluate($this->hidden) ?? false; } + + public function renderUsingHook(string $panelHook): string + { + $this->renderUsingHook = $panelHook; + + return $this; + } } From 649eff642a0e94773f3d2fb0ab985bddfa70a712 Mon Sep 17 00:00:00 2001 From: Abishek R Srikaanth <1639302+abishekrsrikaanth@users.noreply.github.com> Date: Tue, 28 May 2024 10:02:03 +0000 Subject: [PATCH 2/2] Fixing return type for method reunderUsingHook --- src/QuickCreatePlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QuickCreatePlugin.php b/src/QuickCreatePlugin.php index 3c8135b..23ea533 100644 --- a/src/QuickCreatePlugin.php +++ b/src/QuickCreatePlugin.php @@ -195,7 +195,7 @@ public function shouldBeHidden(): bool return $this->evaluate($this->hidden) ?? false; } - public function renderUsingHook(string $panelHook): string + public function renderUsingHook(string $panelHook): static { $this->renderUsingHook = $panelHook;