From 01bc6b8e3097c439b31042e34f483e31f882bd53 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Fri, 18 Aug 2023 13:17:02 +0100 Subject: [PATCH] load the data from submission tableif submission id is passed --- .../Api4/Action/Afform/AbstractProcessor.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php b/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php index cc96c5851d..bbd741f7e7 100644 --- a/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php +++ b/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php @@ -86,6 +86,13 @@ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction { $sorter = new AfformEntitySortEvent($this->_afform, $this->_formDataModel, $this); \Civi::dispatcher()->dispatch('civi.afform.sort.prefill', $sorter); $sortedEntities = $sorter->getSortedEnties(); + + // if submission id is passed then we should display the submission data + if (!empty($this->args['sid'])) { + $this->prePopulateSubmissionData($sortedEntities); + return; + } + foreach ($sortedEntities as $entityName) { $entity = $this->_formDataModel->getEntity($entityName); $this->_entityIds[$entityName] = []; @@ -105,6 +112,25 @@ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction { } } + /** + * Load the data from submission table + */ + protected function prePopulateSubmissionData($sortedEntities) { + // if submission id is passed then get the data from submission + $afformSubmissionData = \Civi\Api4\AfformSubmission::get(TRUE) + ->addSelect('data') + ->addWhere('id', '=', $this->args['sid']) + ->execute()->first(); + + foreach ($sortedEntities as $entityName) { + foreach ($afformSubmissionData['data'] as $entity => $data) { + if ($entity == $entityName) { + $this->_entityValues[$entityName] = $data; + } + } + } + } + /** * Fetch all data needed to display a given entity on this form * -- 2.25.1