From: Kurund Jalmi Date: Fri, 18 Aug 2023 12:17:02 +0000 (+0100) Subject: load the data from submission tableif submission id is passed X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=01bc6b8e3097c439b31042e34f483e31f882bd53;p=civicrm-core.git load the data from submission tableif submission id is passed --- 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 *