Skip to content

[fix] Property access for Modal Executor #1565

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

Merged
merged 1 commit into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions demos/collection/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
// Crud can operate with various fields
\Atk4\Ui\Header::addTo($column, ['Configured Crud']);
$crud = \Atk4\Ui\Crud::addTo($column, [
//'fieldsCreate' => ['name', 'iso', 'iso3', 'numcode', 'phonecode'], // when creating then show more fields
'displayFields' => ['name'], // when updating then only allow to update name
'editFields' => ['name', 'iso', 'iso3'],
'displayFields' => ['name'], // field to display in Crud
'editFields' => ['name', 'iso', 'iso3'], // field to display on 'edit' action
'ipp' => 5,
'paginator' => ['range' => 2, 'class' => ['blue inverted']], // reduce range on the paginator
'menu' => ['class' => ['green inverted']],
Expand Down Expand Up @@ -77,7 +76,7 @@ public function addFormTo(\Atk4\Ui\View $view): \Atk4\Ui\Form
$left = $columns->addColumn();
$right = $columns->addColumn();

$result = parent::addFormTo($left); // TODO: Change the autogenerated stub
$result = parent::addFormTo($left);

if ($this->action->getOwner()->get('is_folder')) {
\Atk4\Ui\Grid::addTo($right, ['menu' => false, 'ipp' => 5])
Expand Down
24 changes: 17 additions & 7 deletions src/UserAction/ModalExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ protected function doArgs(View $modal)
}

// set args value if available.
$this->setFormField($form, $this->actionData['args'] ?? [], $this->step);
$this->setFormField($form, $this->getActionData('args'), $this->step);

// setup exec, next and prev button handler for this step.
$this->jsSetSubmitBtn($modal, $form, $this->step);
Expand All @@ -312,7 +312,7 @@ protected function doFields(View $modal)

$form->setModel($this->action->getOwner(), $this->action->fields);
// set Fields value if set from another step.
$this->setFormField($form, $this->actionData['fields'] ?? [], $this->step);
$this->setFormField($form, $this->getActionData('fields'), $this->step);

// setup exec, next and prev button handler for this step.
$this->jsSetSubmitBtn($modal, $form, $this->step);
Expand All @@ -338,7 +338,7 @@ protected function doPreview(View $modal)
{
$this->_addStepTitle($modal, $this->step);

if ($fields = $this->actionData['fields'] ?? null) {
if ($fields = $this->getActionData('fields')) {
$this->action->getModel()->setMulti($fields);
}

Expand Down Expand Up @@ -397,15 +397,25 @@ protected function doPreview(View $modal)
*/
protected function doFinal(View $modal)
{
foreach ($this->actionData['fields'] ?? [] as $field => $value) {
foreach ($this->getActionData('fields') as $field => $value) {
$this->action->getOwner()->set($field, $value);
}

$return = $this->action->execute(...$this->_getActionArgs($this->actionData['args'] ?? []));
$return = $this->action->execute(...$this->_getActionArgs($this->getActionData('args')));

$this->_jsSequencer($modal, $this->jsGetExecute($return, $this->action->getOwner()->getId()));
}

protected function getActionData(string $step): array
{
return $this->actionData[$step] ?? [];
}

protected function getStep(): string
{
return $this->step;
}

/**
* Return proper js statement need after action execution.
*
Expand Down Expand Up @@ -534,7 +544,7 @@ protected function jsStepSubmit(string $step)
try {
if ($this->isLastStep($step)) {
// collect argument and execute action.
$return = $this->action->execute(...$this->_getActionArgs($this->actionData['args'] ?? []));
$return = $this->action->execute(...$this->_getActionArgs($this->getActionData('args')));
$js = $this->jsGetExecute($return, $this->action->getOwner()->getId());
} else {
// store data and setup reload.
Expand Down Expand Up @@ -678,7 +688,7 @@ protected function getActionPreview()
$args = [];

foreach ($this->action->args as $key => $val) {
$args[] = $this->actionData['args'][$key];
$args[] = $this->getActionData('args')[$key];
}

return $this->action->preview(...$args);
Expand Down