diff --git a/packages/actions/docs/03-modals.md b/packages/actions/docs/03-modals.md index fc908180058..7355b29d1ec 100644 --- a/packages/actions/docs/03-modals.md +++ b/packages/actions/docs/03-modals.md @@ -642,6 +642,20 @@ use Filament\Support\View\Components\Modal; Modal::closedByEscaping(false); ``` +## Hooks for when action modal is closed + +You may want to execute some code before or after the modal is closed. + +```php +Action::make('updateAuthor') + ->beforeClose(function () { + // Do something before the modal is closed. + }) + ->afterClose(function () { + // Do something after the modal is closed. + }) +``` + ## Hiding the modal close button By default, modals have a close button in the top right corner. If you wish to hide the close button, you can use the `modalCloseButton(false)` method: diff --git a/packages/actions/src/Concerns/HasLifecycleHooks.php b/packages/actions/src/Concerns/HasLifecycleHooks.php index f3a4686d754..614240cf3ac 100644 --- a/packages/actions/src/Concerns/HasLifecycleHooks.php +++ b/packages/actions/src/Concerns/HasLifecycleHooks.php @@ -13,6 +13,10 @@ trait HasLifecycleHooks protected ?Closure $after = null; + protected ?Closure $beforeClose = null; + + protected ?Closure $afterClose = null; + protected ?Closure $beforeFormFilled = null; protected ?Closure $afterFormFilled = null; @@ -35,6 +39,20 @@ public function after(?Closure $callback): static return $this; } + public function beforeClose(?Closure $callback): static + { + $this->beforeClose = $callback; + + return $this; + } + + public function afterClose(?Closure $callback): static + { + $this->afterClose = $callback; + + return $this; + } + public function beforeFormFilled(?Closure $callback): static { $this->beforeFormFilled = $callback; @@ -79,6 +97,22 @@ public function callAfter(): mixed } } + public function callBeforeClose(): mixed + { + Event::dispatch(ActionCalling::class, $this); + + return $this->evaluate($this->beforeClose); + } + + public function callAfterClose(): mixed + { + try { + return $this->evaluate($this->afterClose); + } finally { + Event::dispatch(ActionCalled::class, $this); + } + } + public function callBeforeFormFilled(): mixed { return $this->evaluate($this->beforeFormFilled); diff --git a/packages/infolists/src/Components/Entry.php b/packages/infolists/src/Components/Entry.php index 1b9c2b42a88..0fc1281ee36 100644 --- a/packages/infolists/src/Components/Entry.php +++ b/packages/infolists/src/Components/Entry.php @@ -6,6 +6,7 @@ use Exception; use Filament\Actions\Action; use Filament\Schemas\Components\Component; +use Filament\Schemas\Components\Concerns\CanOpenUrl; use Filament\Schemas\Components\Decorations\Layouts\DecorationsLayout; use Filament\Support\Concerns\HasAlignment; use Filament\Support\Concerns\HasPlaceholder; @@ -14,11 +15,11 @@ class Entry extends Component { + use CanOpenUrl; use Concerns\HasExtraEntryWrapperAttributes; use Concerns\HasHelperText; use Concerns\HasHint; use Concerns\HasName; - use \Filament\Schemas\Components\Concerns\CanOpenUrl; use HasAlignment; use HasPlaceholder; use HasTooltip; diff --git a/packages/panels/src/GlobalSearch/Providers/DefaultGlobalSearchProvider.php b/packages/panels/src/GlobalSearch/Providers/DefaultGlobalSearchProvider.php index 9b1b59ac719..5aa08db16ea 100644 --- a/packages/panels/src/GlobalSearch/Providers/DefaultGlobalSearchProvider.php +++ b/packages/panels/src/GlobalSearch/Providers/DefaultGlobalSearchProvider.php @@ -4,9 +4,8 @@ use Filament\Facades\Filament; use Filament\GlobalSearch\GlobalSearchResults; -use Filament\GlobalSearch\Providers; -class DefaultGlobalSearchProvider implements Providers\Contracts\GlobalSearchProvider +class DefaultGlobalSearchProvider implements Contracts\GlobalSearchProvider { public function getResults(string $query): ?GlobalSearchResults { diff --git a/packages/tables/src/Columns/ToggleColumn.php b/packages/tables/src/Columns/ToggleColumn.php index ecc24313b86..ec832f4397b 100644 --- a/packages/tables/src/Columns/ToggleColumn.php +++ b/packages/tables/src/Columns/ToggleColumn.php @@ -125,7 +125,7 @@ public function toEmbeddedHtml(): string
diff --git a/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/EmailCodeAuthenticationChallengeTest.php b/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/EmailCodeAuthenticationChallengeTest.php index 853e9d7e44d..b664650a05a 100644 --- a/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/EmailCodeAuthenticationChallengeTest.php +++ b/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/EmailCodeAuthenticationChallengeTest.php @@ -21,7 +21,7 @@ }); it('can render the challenge form after valid login credentials are successfully used', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasEmailCodeAuthentication() @@ -52,7 +52,7 @@ }); it('will authenticate the user after a valid challenge code is used', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasEmailCodeAuthentication() @@ -79,7 +79,7 @@ }); it('can resend the code to the user', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasEmailCodeAuthentication() @@ -140,7 +140,7 @@ }); it('will not authenticate the user when an invalid challenge code is used', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasEmailCodeAuthentication() @@ -171,7 +171,7 @@ }); test('challenge codes are required', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasEmailCodeAuthentication() @@ -200,7 +200,7 @@ }); test('challenge codes must be numeric', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasEmailCodeAuthentication() @@ -229,7 +229,7 @@ }); test('challenge codes must be 6 digits', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasEmailCodeAuthentication() diff --git a/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/RemoveEmailCodeAuthenticationActionTest.php b/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/RemoveEmailCodeAuthenticationActionTest.php index 6e58b22609c..0d7ee9c858e 100644 --- a/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/RemoveEmailCodeAuthenticationActionTest.php +++ b/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/RemoveEmailCodeAuthenticationActionTest.php @@ -26,7 +26,7 @@ }); it('can remove authentication when valid challenge code is used', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); @@ -76,7 +76,7 @@ }); it('will not remove authentication when an invalid code is used', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); @@ -128,7 +128,7 @@ }); test('codes must be 6 digits', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); diff --git a/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/SetUpEmailCodeAuthenticationActionTest.php b/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/SetUpEmailCodeAuthenticationActionTest.php index dc1442caa69..cd62826e044 100644 --- a/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/SetUpEmailCodeAuthenticationActionTest.php +++ b/tests/src/Panels/Auth/MultiFactorAuthentication/EmailCode/SetUpEmailCodeAuthenticationActionTest.php @@ -24,7 +24,7 @@ }); it('can generate a secret when the action is mounted', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $livewire = livewire(EditProfile::class) ->mountAction(TestAction::make('setUpEmailCodeAuthentication') @@ -58,7 +58,7 @@ }); it('can save the secret to the user when the action is submitted', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); @@ -102,7 +102,7 @@ }); it('will not set up authentication when an invalid code is used', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); @@ -159,7 +159,7 @@ }); test('codes must be 6 digits', function () { - $emailCodeAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $emailCodeAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); diff --git a/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/RegenerateGoogleTwoFactorAuthenticationRecoveryCodesActionTest.php b/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/RegenerateGoogleTwoFactorAuthenticationRecoveryCodesActionTest.php index 00d0b9f0d8f..6e1bc321580 100644 --- a/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/RegenerateGoogleTwoFactorAuthenticationRecoveryCodesActionTest.php +++ b/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/RegenerateGoogleTwoFactorAuthenticationRecoveryCodesActionTest.php @@ -22,7 +22,7 @@ }); it('can generate new recovery codes when valid challenge code is used', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); @@ -114,7 +114,7 @@ }); it('will not generate new recovery codes when an invalid code is used', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); @@ -162,7 +162,7 @@ }); test('codes must be 6 digits', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); diff --git a/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/RemoveGoogleTwoFactorAuthenticationActionTest.php b/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/RemoveGoogleTwoFactorAuthenticationActionTest.php index 5d2a075f37d..96f14d1bec9 100644 --- a/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/RemoveGoogleTwoFactorAuthenticationActionTest.php +++ b/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/RemoveGoogleTwoFactorAuthenticationActionTest.php @@ -16,7 +16,7 @@ beforeEach(function () { Filament::setCurrentPanel('google-two-factor-authentication'); - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $this->recoveryCodes = $googleTwoFactorAuthentication->generateRecoveryCodes(); @@ -26,7 +26,7 @@ }); it('can remove authentication when valid challenge code is used', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); @@ -95,7 +95,7 @@ }); it('will not remove authentication when an invalid code is used', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); @@ -163,7 +163,7 @@ }); test('codes must be 6 digits', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); diff --git a/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/SetUpGoogleTwoFactorAuthenticationActionTest.php b/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/SetUpGoogleTwoFactorAuthenticationActionTest.php index 18114a9a896..a952a62d23b 100644 --- a/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/SetUpGoogleTwoFactorAuthenticationActionTest.php +++ b/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/Actions/SetUpGoogleTwoFactorAuthenticationActionTest.php @@ -60,7 +60,7 @@ }); it('can save the secret and recovery codes to the user when the action is submitted', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); @@ -104,7 +104,7 @@ }); it('will not set up authentication when an invalid code is used', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); @@ -177,7 +177,7 @@ }); test('codes must be 6 digits', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $user = auth()->user(); diff --git a/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/GoogleTwoFactorAuthenticationChallengeTest.php b/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/GoogleTwoFactorAuthenticationChallengeTest.php index 7ca2d499246..ecc3e7c5837 100644 --- a/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/GoogleTwoFactorAuthenticationChallengeTest.php +++ b/tests/src/Panels/Auth/MultiFactorAuthentication/GoogleTwoFactor/GoogleTwoFactorAuthenticationChallengeTest.php @@ -39,7 +39,7 @@ }); it('will authenticate the user after a valid challenge code is used', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasGoogleTwoFactorAuthentication() @@ -66,7 +66,7 @@ }); it('will make the recovery code field visible when the user requests it', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasGoogleTwoFactorAuthentication() @@ -95,7 +95,7 @@ }); it('will authenticate the user after a valid recovery code is used', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasGoogleTwoFactorAuthentication($recoveryCodes = $googleTwoFactorAuthentication->generateRecoveryCodes()) @@ -158,7 +158,7 @@ }); it('will not authenticate the user when an invalid challenge code is used', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasGoogleTwoFactorAuthentication() @@ -189,7 +189,7 @@ }); test('challenge codes are required', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasGoogleTwoFactorAuthentication() @@ -218,7 +218,7 @@ }); test('challenge codes must be numeric', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasGoogleTwoFactorAuthentication() @@ -247,7 +247,7 @@ }); test('challenge codes must be 6 digits', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasGoogleTwoFactorAuthentication() @@ -276,7 +276,7 @@ }); it('will not authenticate the user when an invalid recovery code is used', function () { - $googleTwoFactorAuthentication = Arr::first(filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); + $googleTwoFactorAuthentication = Arr::first(Filament::getCurrentPanel()->getMultiFactorAuthenticationProviders()); $userToAuthenticate = User::factory() ->hasGoogleTwoFactorAuthentication()