-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UserAction StepExecutor improvement #1687
Conversation
src/UserAction/StepExecutorTrait.php
Outdated
*/ | ||
protected function getModelForArgs(): Model | ||
{ | ||
$this->cloneAction = clone $this->getAction(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- argument can be easily validate using a Validator;
- argument can be easily define within a model;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ArgModel::class]
should be probably here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It support both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -167,8 +190,9 @@ protected function doArgs(View $page): void | |||
$this->jsSetPrevHandler($page, $this->step); | |||
|
|||
$form->onSubmit(function (Form $form) { | |||
$form->model->save(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is now save needed?
src/UserAction/StepExecutorTrait.php
Outdated
@@ -72,6 +72,9 @@ trait StepExecutorTrait | |||
/** @var string */ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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