- WIP on form/context init method

This commit is contained in:
Dev 2025-12-02 20:58:13 +00:00
parent 696386bb06
commit ae212a4377
2 changed files with 8 additions and 12 deletions

View File

@ -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

View File

@ -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;
}
}