- Added a new automated Form save
This commit is contained in:
1 parent
899dd1a4d4
commit
2585bc3315
4 files changed
+158
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Form;
|
||||
|
||||
use CSSLSJ\ExamenFga\Api\{Lib};
|
||||
use Picea\Ui\Method\{FormContextInterface};
|
||||
use Ulmus\Entity\EntityInterface;
|
||||
|
||||
class Delete implements \Picea\Ui\Method\FormInterface {
|
||||
|
||||
public function __construct(
|
||||
public EntityInterface $entity,
|
||||
) {}
|
||||
|
||||
public function getEntity() : EntityInterface
|
||||
{
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
public function initialize(FormContextInterface $context) : void {}
|
||||
|
||||
public function validate(FormContextInterface $context) : bool
|
||||
{
|
||||
return $context->valid();
|
||||
}
|
||||
|
||||
public function execute(FormContextInterface $context) : void
|
||||
{
|
||||
try {
|
||||
if ( $this->getEntity()::repository()->destroy($this->getEntity()) ) {
|
||||
$context->pushMessage(Lib\Message::generateSuccess(
|
||||
"Suppression effectué avec succès"
|
||||
));
|
||||
}
|
||||
else {
|
||||
throw new \InvalidArgumentException("Suppression impossible; une erreur semble survenue...");
|
||||
}
|
||||
}
|
||||
catch(\Throwable $ex) {
|
||||
throw new \ErrorException(sprintf("Une erreur est survenue : '%s'", $ex->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user