Afform - Rename submitFile param from entityName to modelName
authorColeman Watts <coleman@civicrm.org>
Wed, 6 Oct 2021 21:26:41 +0000 (17:26 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 7 Oct 2021 04:24:44 +0000 (00:24 -0400)
$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.

ext/afform/core/Civi/Api4/Action/Afform/SubmitFile.php
ext/afform/core/ang/af/afField.component.js
ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php

index bd463b02c26a2c77a244fb3806155aa57aebbb8b..5d1f9753193ab97cde0b9ce315c30b7ca5d88c95 100644 (file)
@@ -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) {
index 34d425c378327a0d740e877e2195e3ecb592678e..5737c1a4a8aed4693b4670b884b49198d455bb83 100644 (file)
       // 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(),
index c8bfb3040d6e8aa2b54e6bf66bf72ed1ce70ea1f..fa706c1cb3428d3228728bceb17a67833a354ed6 100644 (file)
@@ -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')