| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Ui\UserAction; |
| 6: | |
| 7: | use Atk4\Core\Factory; |
| 8: | use Atk4\Data\Model; |
| 9: | use Atk4\Ui\Form; |
| 10: | use Atk4\Ui\Header; |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | class ArgumentFormExecutor extends BasicExecutor |
| 18: | { |
| 19: | |
| 20: | public $form; |
| 21: | |
| 22: | #[\Override] |
| 23: | public function initPreview(): void |
| 24: | { |
| 25: | Header::addTo($this, [$this->action->getCaption(), 'subHeader' => $this->description ?? $this->action->getDescription()]); |
| 26: | $this->form = Form::addTo($this, ['buttonSave' => $this->executorButton]); |
| 27: | |
| 28: | foreach ($this->action->args as $key => $val) { |
| 29: | if ($val instanceof Model) { |
| 30: | $val = ['model' => $val]; |
| 31: | } |
| 32: | |
| 33: | if (isset($val['model'])) { |
| 34: | $val['model'] = Factory::factory($val['model']); |
| 35: | $this->form->addControl($key, [Form\Control\Lookup::class])->setModel($val['model']); |
| 36: | } else { |
| 37: | $this->form->addControl($key, [], $val); |
| 38: | } |
| 39: | } |
| 40: | |
| 41: | $this->form->onSubmit(function (Form $form) { |
| 42: | |
| 43: | $this->setArguments($form->model->get()); |
| 44: | |
| 45: | return $this->executeModelAction(); |
| 46: | }); |
| 47: | } |
| 48: | } |
| 49: | |