Skip to content

Commit

Permalink
Merge pull request #12891 from filamentphp/move-action-lifecycle-hooks
Browse files Browse the repository at this point in the history
Move action lifecycle hooks
  • Loading branch information
danharrin authored May 22, 2024
2 parents dcd1c72 + 00e7c30 commit fe2bc20
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 deletions.
14 changes: 9 additions & 5 deletions packages/actions/src/Concerns/InteractsWithActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,17 @@ public function callMountedAction(array $arguments = []): mixed
if ($this->mountedActionHasForm(mountedAction: $action)) {
$action->callBeforeFormValidated();

$action->formData($form->getState());

$action->callAfterFormValidated();
$action->formData(
$form->getState(afterValidate: function () use ($action) {
$action->callAfterFormValidated();

$action->callBefore();
}),
);
} else {
$action->callBefore();
}

$action->callBefore();

$result = $action->call([
'form' => $form,
]);
Expand Down
14 changes: 9 additions & 5 deletions packages/forms/src/Concerns/HasFormComponentActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ public function callMountedFormComponentAction(array $arguments = []): mixed
if ($this->mountedFormComponentActionHasForm(mountedAction: $action)) {
$action->callBeforeFormValidated();

$action->formData($form->getState());

$action->callAfterFormValidated();
$action->formData(
$form->getState(afterValidate: function () use ($action) {
$action->callAfterFormValidated();

$action->callBefore();
}),
);
} else {
$action->callBefore();
}

$action->callBefore();

$result = $action->call([
'form' => $form,
]);
Expand Down
14 changes: 9 additions & 5 deletions packages/infolists/src/Concerns/InteractsWithInfolists.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,17 @@ public function callMountedInfolistAction(array $arguments = []): mixed
if ($this->mountedInfolistActionHasForm(mountedAction: $action)) {
$action->callBeforeFormValidated();

$action->formData($form->getState());

$action->callAfterFormValidated();
$action->formData(
$form->getState(afterValidate: function () use ($action) {
$action->callAfterFormValidated();

$action->callBefore();
}),
);
} else {
$action->callBefore();
}

$action->callBefore();

$result = $action->call([
'form' => $form,
]);
Expand Down
14 changes: 9 additions & 5 deletions packages/tables/src/Concerns/HasActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,17 @@ public function callMountedTableAction(array $arguments = []): mixed
if ($this->mountedTableActionHasForm(mountedAction: $action)) {
$action->callBeforeFormValidated();

$action->formData($form->getState());

$action->callAfterFormValidated();
$action->formData(
$form->getState(afterValidate: function () use ($action) {
$action->callAfterFormValidated();

$action->callBefore();
}),
);
} else {
$action->callBefore();
}

$action->callBefore();

$result = $action->call([
'form' => $form,
]);
Expand Down
14 changes: 9 additions & 5 deletions packages/tables/src/Concerns/HasBulkActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ public function callMountedTableBulkAction(array $arguments = []): mixed
if ($this->mountedTableBulkActionHasForm(mountedBulkAction: $action)) {
$action->callBeforeFormValidated();

$action->formData($form->getState());

$action->callAfterFormValidated();
$action->formData(
$form->getState(afterValidate: function () use ($action) {
$action->callAfterFormValidated();

$action->callBefore();
}),
);
} else {
$action->callBefore();
}

$action->callBefore();

$result = $action->call([
'form' => $form,
]);
Expand Down

0 comments on commit fe2bc20

Please sign in to comment.