Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Add afterSubmit hook (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 authored Jan 6, 2024
1 parent d715bfd commit 80cbbbc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/Forms/Components/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function submit(): void
$this->callHook('afterValidate');

$this->store();

$this->callHook('afterSubmit');
}

public function check(): void
Expand Down
7 changes: 2 additions & 5 deletions src/Views/Forms/CreateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ abstract class CreateForm extends Form
{
public function submit(): void
{
$this->canCreate($this->modelClass);

parent::submit();

$this->callHook('beforeHandle');
Expand All @@ -15,11 +17,6 @@ public function submit(): void
$this->callHook('afterHandle');
}

protected function beforeValidate(): void
{
$this->canCreate($this->modelClass);
}

protected function set(string $class): void
{
$this->canCreate($class);
Expand Down
9 changes: 2 additions & 7 deletions src/Views/Forms/UpdateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class UpdateForm extends Form
{
public function submit(): void
{
$this->canUpdate($this->model);

parent::submit();

$this->callHook('beforeHandle');
Expand All @@ -19,18 +21,11 @@ public function submit(): void

public function delete(): void
{
throw_if(! $this->model);

$this->canDelete($this->model);

$this->model->delete();
}

protected function beforeValidate(): void
{
$this->canUpdate($this->model);
}

protected function set(Model $model): void
{
$this->canUpdate($model);
Expand Down

0 comments on commit 80cbbbc

Please sign in to comment.