From 37bdfee84c85926c8c105f6392cc8e41e933c2ec Mon Sep 17 00:00:00 2001 From: Boris Glumpler Date: Wed, 10 Jan 2024 21:57:56 +0545 Subject: [PATCH] Moved slug panel config to dedicated methods --- packages/panels/docs/09-configuration.md | 24 +++----- .../panels/src/Panel/Concerns/HasAuth.php | 61 ++++++++++++++++--- .../panels/src/Panel/Concerns/HasTenancy.php | 8 ++- tests/src/SlugsPanelProvider.php | 24 ++++---- 4 files changed, 82 insertions(+), 35 deletions(-) diff --git a/packages/panels/docs/09-configuration.md b/packages/panels/docs/09-configuration.md index 88829a453e..5ef0d30512 100644 --- a/packages/panels/docs/09-configuration.md +++ b/packages/panels/docs/09-configuration.md @@ -212,7 +212,7 @@ public function panel(Panel $panel): Panel ## Changing the default slugs -Filament uses sensible English slugs by default when registering its routes. These can be changed by setting them in their respective config methods. +Filament uses sensible English slugs by default when registering its routes. These can be changed by setting them in the methods below. ```php use Filament\Panel; @@ -221,18 +221,14 @@ public function panel(Panel $panel): Panel { return $panel // ... - ->tenantBillingProvider(slug: 'abrechnung') - ->login(slug: 'einloggen') - ->passwordReset( - requestSlug: 'anfragen', - resetSlug: 'zuruecksetzen', - prefix: 'passwort-ruecksetzung' - ) - ->registration(slug: 'registrieren') - ->emailVerification( - promptSlug: 'auffordern', - verifySlug: 'verifizieren', - prefix: 'email-verifizierung' - ); + ->tenantBillingSlug('abrechnung') + ->loginSlug('einloggen') + ->passwordResetRequestSlug('anfragen') + ->passwordResetSlug('zuruecksetzen') + ->passwordResetPrefix('passwort-ruecksetzung') + ->registrationSlug('registrieren') + ->emailVerificationPromptSlug('auffordern') + ->emailVerificationVerifySlug('verifizieren') + ->emailVerificationPrefix('email-verifizierung'); } ``` diff --git a/packages/panels/src/Panel/Concerns/HasAuth.php b/packages/panels/src/Panel/Concerns/HasAuth.php index 04cf659794..d3b3b6f807 100644 --- a/packages/panels/src/Panel/Concerns/HasAuth.php +++ b/packages/panels/src/Panel/Concerns/HasAuth.php @@ -73,13 +73,30 @@ trait HasAuth /** * @param string | Closure | array | null $promptAction */ - public function emailVerification(string | Closure | array | null $promptAction = EmailVerificationPrompt::class, bool $isRequired = true, string $promptSlug = 'prompt', string $verifySlug = 'verify', string $prefix = 'email-verification'): static + public function emailVerification(string | Closure | array | null $promptAction = EmailVerificationPrompt::class, bool $isRequired = true): static { $this->emailVerificationRouteAction = $promptAction; $this->requiresEmailVerification($isRequired); - $this->emailVerificationPromptRouteSlug = $promptSlug; - $this->emailVerificationVerifyRouteSlug = $verifySlug; + return $this; + } + + public function emailVerificationPromptSlug(string $slug): static + { + $this->emailVerificationPromptRouteSlug = $slug; + + return $this; + } + + public function emailVerificationVerifySlug(string $slug): static + { + $this->emailVerificationVerifyRouteSlug = $slug; + + return $this; + } + + public function emailVerificationPrefix(string $prefix): static + { $this->emailVerificationRoutePrefix = $prefix; return $this; @@ -102,9 +119,15 @@ trait HasAuth /** * @param string | Closure | array | null $action */ - public function login(string | Closure | array | null $action = Login::class, string $slug = 'login'): static + public function login(string | Closure | array | null $action = Login::class): static { $this->loginRouteAction = $action; + + return $this; + } + + public function loginSlug(string $slug): static + { $this->loginRouteSlug = $slug; return $this; @@ -114,14 +137,30 @@ trait HasAuth * @param string | Closure | array | null $requestAction * @param string | Closure | array | null $resetAction */ - public function passwordReset(string | Closure | array | null $requestAction = RequestPasswordReset::class, string | Closure | array | null $resetAction = ResetPassword::class, string $requestSlug = 'request', string $resetSlug = 'reset', string $prefix = 'password-reset'): static + public function passwordReset(string | Closure | array | null $requestAction = RequestPasswordReset::class, string | Closure | array | null $resetAction = ResetPassword::class): static { $this->requestPasswordResetRouteAction = $requestAction; $this->resetPasswordRouteAction = $resetAction; - $this->requestPasswordResetRouteSlug = $requestSlug; - $this->resetPasswordRouteSlug = $resetSlug; + return $this; + } + public function passwordResetRequestSlug(string $slug): static + { + $this->requestPasswordResetRouteSlug = $slug; + + return $this; + } + + public function passwordResetSlug(string $slug): static + { + $this->resetPasswordRouteSlug = $slug; + + return $this; + } + + public function passwordResetPrefix(string $prefix): static + { $this->resetPasswordRoutePrefix = $prefix; return $this; @@ -130,9 +169,15 @@ trait HasAuth /** * @param string | Closure | array | null $action */ - public function registration(string | Closure | array | null $action = Register::class, string $slug = 'register'): static + public function registration(string | Closure | array | null $action = Register::class): static { $this->registrationRouteAction = $action; + + return $this; + } + + public function registrationSlug(string $slug): static + { $this->registrationRouteSlug = $slug; return $this; diff --git a/packages/panels/src/Panel/Concerns/HasTenancy.php b/packages/panels/src/Panel/Concerns/HasTenancy.php index 5cd0a72304..3e2c899673 100644 --- a/packages/panels/src/Panel/Concerns/HasTenancy.php +++ b/packages/panels/src/Panel/Concerns/HasTenancy.php @@ -79,9 +79,15 @@ trait HasTenancy return $this; } - public function tenantBillingProvider(?BillingProvider $provider, string $slug = 'billing'): static + public function tenantBillingProvider(?BillingProvider $provider): static { $this->tenantBillingProvider = $provider; + + return $this; + } + + public function tenantBillingSlug(string $slug): static + { $this->tenantBillingRouteSlug = $slug; return $this; diff --git a/tests/src/SlugsPanelProvider.php b/tests/src/SlugsPanelProvider.php index 75694ba4e1..773e31b756 100644 --- a/tests/src/SlugsPanelProvider.php +++ b/tests/src/SlugsPanelProvider.php @@ -22,18 +22,18 @@ class SlugsPanelProvider extends PanelProvider return $panel ->id('slugs') ->path('slugs') - ->login(slug: 'login-test') - ->passwordReset( - requestSlug: 'request-test', - resetSlug: 'reset-test', - prefix: 'password-reset-test' - ) - ->registration(slug: 'register-test') - ->emailVerification( - promptSlug: 'prompt-test', - verifySlug: 'verify-test', - prefix: 'email-verification-test' - ) + ->login() + ->loginSlug('login-test') + ->passwordReset() + ->passwordResetRequestSlug('request-test') + ->passwordResetSlug('reset-test') + ->passwordResetPrefix('password-reset-test') + ->registration() + ->registrationSlug('register-test') + ->emailVerification() + ->emailVerificationPromptSlug('prompt-test') + ->emailVerificationVerifySlug('verify-test') + ->emailVerificationPrefix('email-verification-test') ->resources([]) ->pages([]) ->middleware([