-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from dotkernel/issue-241
Refactored handler
- Loading branch information
Showing
18 changed files
with
233 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frontend\Admin\Form; | ||
|
||
use Frontend\Admin\InputFilter\AdminDeleteInputFilter; | ||
use Laminas\Form\Form; | ||
use Laminas\Form\FormInterface; | ||
use Laminas\InputFilter\InputFilterInterface; | ||
|
||
/** @template-extends Form<FormInterface> */ | ||
class AdminDeleteForm extends Form | ||
{ | ||
protected InputFilterInterface $inputFilter; | ||
|
||
public function __construct(?string $name = null, array $options = []) | ||
{ | ||
parent::__construct($name, $options); | ||
|
||
$this->init(); | ||
|
||
$this->inputFilter = new AdminDeleteInputFilter(); | ||
$this->inputFilter->init(); | ||
} | ||
|
||
public function init(): void | ||
{ | ||
$this->add([ | ||
'name' => 'confirmation', | ||
'type' => 'checkbox', | ||
'options' => [ | ||
'label' => 'Confirmation', | ||
'checked_value' => 'yes', | ||
'unchecked_value' => 'no', | ||
], | ||
'attributes' => [ | ||
'value' => 'no', | ||
'id' => 'confirmation', | ||
'class' => 'form-check-input', | ||
], | ||
]); | ||
|
||
$this->add([ | ||
'name' => 'close', | ||
'type' => 'button', | ||
'options' => [ | ||
'label' => 'Close', | ||
], | ||
'attributes' => [ | ||
'class' => 'btn btn-default', | ||
'data-bs-dismiss' => 'modal', | ||
'role' => 'button', | ||
], | ||
]); | ||
|
||
$this->add([ | ||
'name' => 'submit', | ||
'type' => 'submit', | ||
'attributes' => [ | ||
'class' => 'btn btn-danger', | ||
'id' => 'modalDeleteBtn', | ||
'value' => 'Delete', | ||
], | ||
]); | ||
} | ||
|
||
public function getInputFilter(): InputFilterInterface | ||
{ | ||
return $this->inputFilter; | ||
} | ||
|
||
public function setInputFilter(InputFilterInterface $inputFilter): void | ||
{ | ||
$this->inputFilter = $inputFilter; | ||
$this->inputFilter->init(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frontend\Admin\InputFilter; | ||
|
||
use Laminas\InputFilter\Input; | ||
use Laminas\InputFilter\InputFilter; | ||
use Laminas\Validator\InArray; | ||
use Laminas\Validator\NotEmpty; | ||
|
||
/** @extends InputFilter<object> */ | ||
class AdminDeleteInputFilter extends InputFilter | ||
{ | ||
public function init(): void | ||
{ | ||
$confirmation = new Input('confirmation'); | ||
$confirmation->setRequired(true); | ||
$confirmation->getValidatorChain()->attachByName(NotEmpty::class, [ | ||
'break_chain_on_failure' => true, | ||
'message' => 'Please confirm admin deletion.', | ||
]); | ||
|
||
$confirmation->getValidatorChain()->attachByName(InArray::class, [ | ||
'haystack' => [ | ||
'yes', | ||
], | ||
'break_chain_on_failure' => true, | ||
'message' => 'Please confirm the admin deletion.', | ||
]); | ||
|
||
$this->add($confirmation); | ||
} | ||
} |
Oops, something went wrong.