From 00dcc3f960135ea4f89aa3abff3c0019df15e488 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Tue, 22 Aug 2023 17:50:08 +0100 Subject: [PATCH] change the saving submitted values --- .../Civi/Afform/Event/AfformEventEntityTrait.php | 2 +- .../Civi/Api4/Action/Afform/AbstractProcessor.php | 12 ++++++------ .../core/Civi/Api4/Action/Afform/SubmitFile.php | 2 +- .../phpunit/api/v4/Afform/AfformContactUsageTest.php | 10 +++++----- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ext/afform/core/Civi/Afform/Event/AfformEventEntityTrait.php b/ext/afform/core/Civi/Afform/Event/AfformEventEntityTrait.php index c48849a434..864e98c6a3 100644 --- a/ext/afform/core/Civi/Afform/Event/AfformEventEntityTrait.php +++ b/ext/afform/core/Civi/Afform/Event/AfformEventEntityTrait.php @@ -105,7 +105,7 @@ trait AfformEventEntityTrait { */ public function setJoinIds($index, $joinEntity, $joinIds) { $idField = CoreUtil::getIdFieldName($joinEntity); - $this->entityIds[$this->entityName][$index]['_joins'][$joinEntity] = \CRM_Utils_Array::filterColumns($joinIds, [$idField]); + $this->entityIds[$this->entityName][$index]['joins'][$joinEntity] = \CRM_Utils_Array::filterColumns($joinIds, [$idField]); return $this; } diff --git a/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php b/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php index d2fbf53f31..3e29c775ea 100644 --- a/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php +++ b/ext/afform/core/Civi/Api4/Action/Afform/AbstractProcessor.php @@ -50,7 +50,7 @@ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction { * Each key in the array corresponds to the name of an entity, * and the value is an array of arrays * (because of `` all entities are treated as if they may be multi) - * E.g. $entityIds['Individual1'] = [['id' => 1, '_joins' => ['Email' => [['id' => 1], ['id' => 2]]]; + * E.g. $entityIds['Individual1'] = [['id' => 1, 'joins' => ['Email' => [['id' => 1], ['id' => 2]]]; * * @var array */ @@ -122,10 +122,9 @@ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction { ->addSelect('data') ->addWhere('id', '=', $this->args['sid']) ->addWhere('afform_name', '=', $this->name) - ->addWhere('status_id:name', '=', 'Pending') ->execute()->first(); - // do nothing and return early for invalid submission id + // do nothing and return early if (empty($afformSubmissionData)) { // unset sid from args $this->args['sid'] = NULL; @@ -183,7 +182,7 @@ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction { 'limit' => !empty($join['af-repeat']) ? $join['max'] ?? 0 : 1, 'orderBy' => self::getEntityField($joinEntity, 'is_primary') ? ['is_primary' => 'DESC'] : [], ])); - $this->_entityIds[$entity['name']][$index]['_joins'][$joinEntity] = \CRM_Utils_Array::filterColumns($data['joins'][$joinEntity], [$joinIdField]); + $this->_entityIds[$entity['name']][$index]['joins'][$joinEntity] = \CRM_Utils_Array::filterColumns($data['joins'][$joinEntity], [$joinIdField]); } $this->_entityValues[$entity['name']][$index] = $data; } @@ -390,9 +389,10 @@ abstract class AbstractProcessor extends \Civi\Api4\Generic\AbstractAction { foreach ($value as $idx => $val) { $idData = $ids[$name][$idx] ?? []; if (!$isJoin) { - $idData['_joins'] = $this->combineValuesAndIds($val['joins'] ?? [], $idData['_joins'] ?? [], TRUE); + $idData['joins'] = $this->combineValuesAndIds($val['joins'] ?? [], $idData['joins'] ?? [], TRUE); } - $item = array_merge($isJoin ? $val : ($val['fields'] ?? []), $idData); + // $item = array_merge($isJoin ? $val : ($val['fields'] ?? []), $idData); + $item = array_merge(($val ?? []), $idData); $combined[$name][$idx] = $item; } } diff --git a/ext/afform/core/Civi/Api4/Action/Afform/SubmitFile.php b/ext/afform/core/Civi/Api4/Action/Afform/SubmitFile.php index 3ccfdd9ff5..05218b3d53 100644 --- a/ext/afform/core/Civi/Api4/Action/Afform/SubmitFile.php +++ b/ext/afform/core/Civi/Api4/Action/Afform/SubmitFile.php @@ -70,7 +70,7 @@ class SubmitFile extends AbstractProcessor { $joinIndex = (int) $this->joinIndex; $idField = CoreUtil::getIdFieldName($apiEntity); if ($this->joinEntity) { - $entityId = $this->_entityIds[$this->modelName][$entityIndex]['_joins'][$this->joinEntity][$joinIndex][$idField] ?? NULL; + $entityId = $this->_entityIds[$this->modelName][$entityIndex]['joins'][$this->joinEntity][$joinIndex][$idField] ?? NULL; } else { $entityId = $this->_entityIds[$this->modelName][$entityIndex][$idField] ?? NULL; diff --git a/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformContactUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformContactUsageTest.php index 1528c5852c..e63c67e50d 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformContactUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/Afform/AfformContactUsageTest.php @@ -393,11 +393,11 @@ EOHTML; $this->assertEquals($contact['id'], $submission['data']['Individual1'][0]['id']); $this->assertEquals($contact['org.id'], $submission['data']['Organization1'][0]['id']); $this->assertEquals('Organization1', $submission['data']['Individual1'][0]['employer_id']); - $this->assertEquals($contact['email_primary'], $submission['data']['Individual1'][0]['_joins']['Email'][0]['id']); - $this->assertEquals($individualEmail, $submission['data']['Individual1'][0]['_joins']['Email'][0]['email']); - $this->assertEquals($locationType, $submission['data']['Individual1'][0]['_joins']['Email'][0]['location_type_id']); - $this->assertEquals($orgEmail, $submission['data']['Organization1'][0]['_joins']['Email'][0]['email']); - $this->assertEquals($locationType, $submission['data']['Organization1'][0]['_joins']['Email'][0]['location_type_id']); + $this->assertEquals($contact['email_primary'], $submission['data']['Individual1'][0]['joins']['Email'][0]['id']); + $this->assertEquals($individualEmail, $submission['data']['Individual1'][0]['joins']['Email'][0]['email']); + $this->assertEquals($locationType, $submission['data']['Individual1'][0]['joins']['Email'][0]['location_type_id']); + $this->assertEquals($orgEmail, $submission['data']['Organization1'][0]['joins']['Email'][0]['email']); + $this->assertEquals($locationType, $submission['data']['Organization1'][0]['joins']['Email'][0]['location_type_id']); } public function testDedupeIndividual(): void { -- 2.25.1