1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace Atk4\Ui\UserAction;
6:
7: use Atk4\Data\Model;
8:
9: trait CommonExecutorTrait
10: {
11: protected function executeModelActionLoad(Model\UserAction $action): Model\UserAction
12: {
13: $model = $action->getModel();
14:
15: $id = $this->getApp()->uiPersistence->typecastLoadField(
16: $model->getField($model->idField),
17: $this->stickyGet($this->name)
18: );
19:
20: if ($id && $action->appliesTo === Model\UserAction::APPLIES_TO_SINGLE_RECORD) {
21: if ($action->isOwnerEntity() && $action->getEntity()->getId()) {
22: $action->getEntity()->setId($id); // assert ID is the same
23: } else {
24: $action = $action->getActionForEntity($model->load($id));
25: }
26: } elseif (!$action->isOwnerEntity() && in_array($action->appliesTo, [Model\UserAction::APPLIES_TO_NO_RECORDS, Model\UserAction::APPLIES_TO_SINGLE_RECORD], true)) {
27: $action = $action->getActionForEntity($model->createEntity());
28: }
29:
30: if ($action->fields === true) {
31: $action->fields = array_keys($model->getFields('editable'));
32: }
33:
34: return $action;
35: }
36: }
37: