WIP Submit api
authorColeman Watts <coleman@civicrm.org>
Thu, 12 Sep 2019 01:02:59 +0000 (21:02 -0400)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:19 +0000 (19:13 -0700)
ext/afform/core/Civi/Api4/Action/Afform/Submit.php [new file with mode: 0644]
ext/afform/core/ang/af/ModelList.js

diff --git a/ext/afform/core/Civi/Api4/Action/Afform/Submit.php b/ext/afform/core/Civi/Api4/Action/Afform/Submit.php
new file mode 100644 (file)
index 0000000..94241a1
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+namespace Civi\Api4\Action\Afform;
+
+/**
+ * Class Submit
+ * @package Civi\Api4\Action\Afform
+ */
+class Submit extends AbstractProcessor {
+
+  /**
+   * Submitted values
+   * @var array
+   * @required
+   */
+  protected $values;
+
+  /**
+   * @var array
+   */
+  protected $_submission = [];
+
+  protected function processForm() {
+    foreach ($this->_afformEntities as $entityName => $entity) {
+      // Predetermined values override submitted values
+      $this->_submission[$entity['af-type']][$entityName] = ($entity['af-values'] ?? []) + ($this->values[$entityName] ?? []);
+    }
+    // Determines the order in which to process entities. Contacts go first.
+    $entitiesToProcess = [
+      'Contact' => 'processContacts',
+      'Activity' => 'processActivities',
+    ];
+    foreach ($entitiesToProcess as $entityType => $callback) {
+      if (!empty($this->_submission[$entityType])) {
+        $this->$callback($this->_submission[$entityType]);
+      }
+    }
+    foreach (array_diff_key($this->_submission, $entitiesToProcess) as $entityType) {
+
+    }
+  }
+
+  protected function processGenericEntity($entityType, $items) {
+    foreach ($items as $name => $item) {
+      civicrm_api4($entityType, 'save', $items);
+    }
+  }
+
+  protected function processContacts($contacts) {
+    foreach ($contacts as $name => $contact) {
+
+    }
+  }
+
+}
index 03652da7aea51c60d8e003e524428a3e7af456d6..ef696de09098e61f8528d2c79f09dc46959e6921 100644 (file)
@@ -55,7 +55,7 @@
         };
 
         this.submit = function submit() {
-          CRM.alert('TODO: Submit');
+          crmApi4('Afform', 'submit', {name: CRM.afform.open, args: $routeParams, values: data});
         };
       }
     };