Add APIv4 Batch.create spec
authorMonish Deb <monish.deb@jmaconsulting.biz>
Fri, 4 Jun 2021 07:12:08 +0000 (12:42 +0530)
committerMonish Deb <monish.deb@jmaconsulting.biz>
Fri, 4 Jun 2021 19:31:58 +0000 (01:01 +0530)
Civi/Api4/Service/Spec/Provider/BatchCreationSpecProvider.php [new file with mode: 0644]
api/v3/Batch.php

diff --git a/Civi/Api4/Service/Spec/Provider/BatchCreationSpecProvider.php b/Civi/Api4/Service/Spec/Provider/BatchCreationSpecProvider.php
new file mode 100644 (file)
index 0000000..d45ae81
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ */
+
+
+namespace Civi\Api4\Service\Spec\Provider;
+
+use Civi\Api4\Service\Spec\RequestSpec;
+
+class BatchCreationSpecProvider implements Generic\SpecProviderInterface {
+
+  /**
+   * @inheritDoc
+   */
+  public function modifySpec(RequestSpec $spec) {
+    $spec->getFieldByName('created_id')->setDefaultValue('user_contact_id');
+    $spec->getFieldByName('created_date')->setDefaultValue('now');
+    $spec->getFieldByName('modified_id')->setDefaultValue('user_contact_id');
+    $spec->getFieldByName('modified_date')->setDefaultValue('now');
+  }
+
+  /**
+   * @inheritDoc
+   */
+  public function applies($entity, $action) {
+    return $entity === 'Batch' && $action === 'create';
+  }
+
+}
index 8eedd8242907617eb8bb423c95a3bf9e0ef7194b..0b68afe41514126607020ec44d3d95f90dc9930e 100644 (file)
@@ -37,11 +37,6 @@ function civicrm_api3_batch_create($params) {
  *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_batch_create_spec(&$params) {
-  //@todo - the entity table field looks like it is not actually required & should probably be removed (or a description added if
-  // it is actually required)
-  $params['entity_table']['api.default'] = "civicrm_batch";
-  $params['entity_table']['type'] = CRM_Utils_Type::T_STRING;
-  $params['entity_table']['title'] = 'Batch Entity Table - remove?';
   $params['created_id']['api.default'] = 'user_contact_id';
   $params['created_date']['api.default'] = 'now';
   $params['modified_id']['api.default'] = 'user_contact_id';