- WIP on form/context init method
This commit is contained in:
parent
696386bb06
commit
ae212a4377
@ -18,7 +18,7 @@ class ContextField
|
||||
public ?string $regexFormat = null,
|
||||
public ?string $example = null,
|
||||
public bool $hidden = false,
|
||||
public mixed $default = false,
|
||||
public mixed $default = null,
|
||||
) {}
|
||||
|
||||
public function assertValueSpecs(mixed $value, bool $isNew) : void
|
||||
|
||||
@ -23,13 +23,12 @@ abstract class Save extends Form implements \Picea\Ui\Method\FormInterface {
|
||||
|
||||
public function initialize(FormContextInterface $context) : void
|
||||
{
|
||||
if ( ! $this->getEntity()->isLoaded() || $context->formSent() ) {
|
||||
if ( ! $this->getEntity()->isLoaded() ) {
|
||||
if (method_exists($context, 'initializeEntity')) {
|
||||
$context->initializeEntity($this->getEntity());
|
||||
}
|
||||
else {
|
||||
$this->assignContextToEntity($context);
|
||||
}
|
||||
|
||||
$this->assignContextToEntity($context);
|
||||
}
|
||||
|
||||
parent::initialize($context);
|
||||
@ -62,21 +61,17 @@ abstract class Save extends Form implements \Picea\Ui\Method\FormInterface {
|
||||
$this->assignContextToEntity($context);
|
||||
|
||||
if ( $saved = $entity::repository()->save($entity) ) {
|
||||
$context->pushMessage($this->message::generateSuccess(
|
||||
$this->lang('lean.api.form.save.success.save')
|
||||
));
|
||||
$context->pushSuccessMessage('lean.api.form.save.success.save');
|
||||
}
|
||||
else {
|
||||
$context->pushMessage($this->message::generateWarning(
|
||||
$this->lang('lean.api.form.save.warning.entity', [ 'entity' => substr($this->entity::class, strrpos($this->entity::class, '\\') + 1) ])
|
||||
));
|
||||
$context->pushWarningMessage('lean.api.form.save.warning.entity', [ 'entity' => substr($this->entity::class, strrpos($this->entity::class, '\\') + 1) ]);
|
||||
}
|
||||
}
|
||||
catch(\PDOException $ex) {
|
||||
throw new \PDOException($this->lang('lean.api.form.save.error.pdo', [ 'error' => $ex->getMessage() ]));
|
||||
}
|
||||
catch(\Throwable $ex) {
|
||||
throw $ex;
|
||||
$context->pushErrorMessage($ex->getMessage());
|
||||
}
|
||||
|
||||
return $saved;
|
||||
@ -130,6 +125,7 @@ abstract class Save extends Form implements \Picea\Ui\Method\FormInterface {
|
||||
|
||||
if ($contextField) {
|
||||
if (isset($contextField->object->default)) {
|
||||
|
||||
$entity->$key = $contextField->object->default;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user