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