Skip to content

Commit 3ed0ae5

Browse files
authored
Merge pull request #9 from ainesophaur/bugfix/blade-rendering-issue
Plugin issue with multiple panels
2 parents d16f93f + 3041739 commit 3ed0ae5

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

src/FilamentDeveloperLoginsServiceProvider.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DutchCodingCompany\FilamentDeveloperLogins\Livewire\MenuLogins;
66
use DutchCodingCompany\FilamentDeveloperLogins\View\Components\DeveloperLogins;
77
use Filament\Facades\Filament;
8+
use Filament\Panel;
89
use Filament\Support\Concerns\EvaluatesClosures;
910
use Filament\Support\Facades\FilamentView;
1011
use Filament\View\PanelsRenderHook;
@@ -44,17 +45,16 @@ public function packageBooted(): void
4445

4546
protected static function registerRenderHooks(): void
4647
{
47-
$panel = Filament::getCurrentPanel();
48-
if (is_null($panel) || ! $panel->hasPlugin('filament-developer-logins')) {
49-
return;
50-
}
51-
52-
/** @var FilamentDeveloperLoginsPlugin $plugin */
53-
$plugin = $panel->getPlugin('filament-developer-logins');
54-
5548
FilamentView::registerRenderHook(
5649
PanelsRenderHook::AUTH_LOGIN_FORM_AFTER,
57-
static function () use ($plugin) : ?string {
50+
static function (): ?string {
51+
$panel = Filament::getCurrentPanel();
52+
if (! self::panelHasPlugin($panel)) {
53+
return null;
54+
}
55+
56+
/** @var FilamentDeveloperLoginsPlugin $plugin */
57+
$plugin = $panel->getPlugin('filament-developer-logins');
5858
if (! $plugin->getEnabled()) {
5959
return null;
6060
}
@@ -65,7 +65,14 @@ static function () use ($plugin) : ?string {
6565

6666
FilamentView::registerRenderHook(
6767
PanelsRenderHook::GLOBAL_SEARCH_AFTER,
68-
static function () use ($plugin) : ?string {
68+
static function (): ?string {
69+
$panel = Filament::getCurrentPanel();
70+
if (! self::panelHasPlugin($panel)) {
71+
return null;
72+
}
73+
74+
/** @var FilamentDeveloperLoginsPlugin $plugin */
75+
$plugin = $panel->getPlugin('filament-developer-logins');
6976
if (! $plugin->getEnabled() || ! $plugin->getSwitchable()) {
7077
return null;
7178
}
@@ -74,4 +81,9 @@ static function () use ($plugin) : ?string {
7481
},
7582
);
7683
}
84+
85+
protected static function panelHasPlugin(?Panel $panel): bool
86+
{
87+
return ! is_null($panel) && $panel->hasPlugin('filament-developer-logins');
88+
}
7789
}

tests/Feature/MenuLoginsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use DutchCodingCompany\FilamentDeveloperLogins\Tests\TestCase;
99
use Filament\Facades\Filament;
1010
use Filament\Pages\Dashboard;
11+
use Filament\Panel;
1112
use Livewire\Livewire;
1213

1314
final class MenuLoginsTest extends TestCase
@@ -80,4 +81,19 @@ public function test_forbidden_is_returned_when_enabled_or_switchable_is_false()
8081
->call('loginAs', '[email protected]')
8182
->assertForbidden();
8283
}
84+
85+
public function test_component_is_only_rendered_in_panel_with_plugin(): void
86+
{
87+
$user = TestUser::factory()->create();
88+
89+
$this->actingAs($user)
90+
->get(Dashboard::getUrl(panel: $this->panelName))
91+
->assertSuccessful()
92+
->assertSeeLivewire(MenuLogins::class);
93+
94+
$this->actingAs($user)
95+
->get(Dashboard::getUrl(panel: $this->panelName.'-other'))
96+
->assertSuccessful()
97+
->assertDontSeeLivewire(MenuLogins::class);
98+
}
8399
}

tests/TestCase.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function setUp(): void
3636
);
3737
}
3838

39-
protected function registerTestPanel(): void
39+
protected function registerTestPanels(): void
4040
{
4141
Filament::registerPanel(
4242
fn (): Panel => Panel::make()
@@ -57,6 +57,18 @@ protected function registerTestPanel(): void
5757
->modelClass(TestUser::class),
5858
]),
5959
);
60+
61+
Filament::registerPanel(fn () => Panel::make()
62+
->darkMode(false)
63+
->id($this->panelName.'-other')
64+
->path($this->panelName.'-other')
65+
->login()
66+
->pages([
67+
Dashboard::class,
68+
])
69+
->plugins([
70+
]),
71+
);
6072
}
6173

6274
protected function defineRoutes($router): void
@@ -80,7 +92,7 @@ protected function getEnvironmentSetUp($app): void
8092

8193
protected function getPackageProviders($app): array
8294
{
83-
$this->registerTestPanel();
95+
$this->registerTestPanels();
8496

8597
return [
8698
FilamentServiceProvider::class,

0 commit comments

Comments
 (0)