Conversation
src/UserAction/StepExecutorTrait.php
Outdated
| */ | ||
| protected function getModelForArgs(): Model | ||
| { | ||
| $this->cloneAction = clone $this->getAction(); |
There was a problem hiding this comment.
why do we need to clone, what is the purpose of using cloned&modified action internally?
this can lead also to many bugs when the action is semi-shallowly cloned, like when it has Closures bound still to the original action
There was a problem hiding this comment.
Cloning was to duplicate Action arguments when set by model only, i.e. each editable model field need to be added as an argument to the UserAction. However, I realized I do not need to clone UserAction but only it's arguments.
A fix is on the way.
| $argsModel = Factory::factory($args['__atk_model']); | ||
| // if seed is supplied, we need to initialize. | ||
| if (!$argsModel->_initialized) { | ||
| $argsModel->invokeInit(); |
There was a problem hiding this comment.
Model::init is invoked when persistence is set
when not initialized, I belive we should set new Array_([]) persistence instead
side question, when custom model for args does bring any advantage?
There was a problem hiding this comment.
- argument can be easily validate using a Validator;
- argument can be easily define within a model;
There was a problem hiding this comment.
when not initialized, I belive we should set
new Array_([])persistence instead
If using seed then developper should supply proper property within the seed array, including Persistence.
demos/_includes/DemoActionsUtil.php
Outdated
| 'caption' => 'Arg with Model', | ||
| 'description' => 'Ask for Arguments set via a Data\Model. Allow usage of model validate() for your arguments', | ||
| 'args' => [ | ||
| '__atk_model' => new ArgModel(new Array_([])), |
There was a problem hiding this comment.
[ArgModel::class] should be probably here
There was a problem hiding this comment.
yes, more like recommended usage ;-)
|
Question: Then executor can check for both UserAction property ($arg and $argModel) accordingly. |
I think lets use/stay with |
|
I am currently checking passing the entire $argModel to callback function as well instead of passing $args separately. |
fcdee8f to
8722647
Compare
src/UserAction/StepExecutorTrait.php
Outdated
| $this->jsSetPrevHandler($page, $this->step); | ||
|
|
||
| $form->onSubmit(function (Form $form) { | ||
| $form->model->save(); |
src/UserAction/StepExecutorTrait.php
Outdated
| public $finalMsg = 'Complete!'; | ||
|
|
||
| /** @var array An extended copy of UserAction arguments. It contains original action arguments and arguments set by '__atk_model'. */ | ||
| private $cloneArgs; |
There was a problem hiding this comment.
I think we should add native Model args support to atk4/data model. It is also not completely clear to me, why there are args & fields. In atk4/data, the UserAction::$fields property is described to be used for dirty detection only.
8688dc7 to
d0ab1c3
Compare
| * @property string $city @Atk4\Field() | ||
| * @property string $gender @Atk4\Field() | ||
| */ | ||
| class ArgModel extends Model |
There was a problem hiding this comment.
our testing/demos Model should be used here to test if field aliasing is used properly
|
I like the idea, however this should be addressed mainly in atk4/data. Then adjusting atk4/ui is an easy job. As it seems you do not plan to work on this topic in the near future, I am closing this PR. Thank you for understanding. |
Fix #1680