From 9474f846a4f0da92e6c1f53b7f56bc49efc2539f Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 6 Oct 2021 17:26:41 -0400 Subject: [PATCH] Afform - Rename submitFile param from entityName to modelName $entityName is already a private property of APIv4 and has its own getter which conflicted with a getter for a param named $entityName. Better to just rename it. --- .../core/Civi/Api4/Action/Afform/SubmitFile.php | 16 +++++++++++----- ext/afform/core/ang/af/afField.component.js | 2 +- .../phpunit/api/v4/AfformFileUploadTest.php | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ext/afform/core/Civi/Api4/Action/Afform/SubmitFile.php b/ext/afform/core/Civi/Api4/Action/Afform/SubmitFile.php index bd463b02c2..5d1f975319 100644 --- a/ext/afform/core/Civi/Api4/Action/Afform/SubmitFile.php +++ b/ext/afform/core/Civi/Api4/Action/Afform/SubmitFile.php @@ -12,10 +12,16 @@ use Civi\Api4\Utils\CoreUtil; * * @method $this setToken(string $token) * @method $this setFieldName(string $fieldName) - * @method $this setEntityName(string $entityName) + * @method $this setModelName(string $modelName) * @method $this setJoinEntity(string $joinEntity) * @method $this setEntityIndex(int $entityIndex) * @method $this setJoinIndex(int $joinIndex) + * @method string getToken() + * @method string getFieldName() + * @method string getModelName() + * @method string getJoinEntity() + * @method int getEntityIndex() + * @method int getJoinIndex() * @package Civi\Api4\Action\Afform */ class SubmitFile extends AbstractProcessor { @@ -31,7 +37,7 @@ class SubmitFile extends AbstractProcessor { * @var string * @required */ - protected $entityName; + protected $modelName; /** * @var string @@ -58,15 +64,15 @@ class SubmitFile extends AbstractProcessor { if (empty($_FILES['file'])) { throw new \API_Exception('File upload required'); } - $afformEntity = $this->_formDataModel->getEntity($this->entityName); + $afformEntity = $this->_formDataModel->getEntity($this->modelName); $apiEntity = $this->joinEntity ?: $afformEntity['type']; $entityIndex = (int) $this->entityIndex; $joinIndex = (int) $this->joinIndex; if ($this->joinEntity) { - $entityId = $this->_entityIds[$this->entityName][$entityIndex]['joins'][$this->joinEntity][$joinIndex] ?? NULL; + $entityId = $this->_entityIds[$this->modelName][$entityIndex]['joins'][$this->joinEntity][$joinIndex] ?? NULL; } else { - $entityId = $this->_entityIds[$this->entityName][$entityIndex]['id'] ?? NULL; + $entityId = $this->_entityIds[$this->modelName][$entityIndex]['id'] ?? NULL; } if (!$entityId) { diff --git a/ext/afform/core/ang/af/afField.component.js b/ext/afform/core/ang/af/afField.component.js index 34d425c378..5737c1a4a8 100644 --- a/ext/afform/core/ang/af/afField.component.js +++ b/ext/afform/core/ang/af/afField.component.js @@ -172,7 +172,7 @@ // Params for the Afform.submitFile API when uploading a file field ctrl.getFileUploadParams = function() { return { - entityName: ctrl.afFieldset.modelName, + modelName: ctrl.afFieldset.getName(), fieldName: ctrl.fieldName, joinEntity: ctrl.afJoin ? ctrl.afJoin.entity : null, entityIndex: ctrl.getEntityIndex(), diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php index c8bfb3040d..fa706c1cb3 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php @@ -110,7 +110,7 @@ EOHTML; Civi\Api4\Afform::submitFile() ->setName($this->formName) ->setToken($submission['token']) - ->setEntityName('Individual1') + ->setModelName('Individual1') ->setFieldName('MyInfo.single_file_field') ->setEntityIndex($entityIndex) ->execute(); @@ -120,7 +120,7 @@ EOHTML; Civi\Api4\Afform::submitFile() ->setName($this->formName) ->setToken($submission['token']) - ->setEntityName('Individual1') + ->setModelName('Individual1') ->setFieldName('my_file') ->setEntityIndex($entityIndex) ->setJoinEntity('Custom_MyFiles') -- 2.25.1