CRM-14055 - Allow creating an event template via api
authorColeman Watts <coleman@civicrm.org>
Sun, 2 Aug 2015 02:50:55 +0000 (22:50 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 3 Aug 2015 18:11:56 +0000 (14:11 -0400)
api/v3/Event.php
tests/phpunit/api/v3/EventTest.php

index 4728270b45361f3c8dcc16dd2cae943839d67647..b6c24ff5ee156c96a4550261b204f06983c6ab6a 100644 (file)
  *   API result Array.
  */
 function civicrm_api3_event_create($params) {
-  civicrm_api3_verify_one_mandatory($params, NULL, array('event_type_id', 'template_id'));
+  // Required fields for creating an event
+  if (empty($params['id']) && empty($params['is_template'])) {
+    civicrm_api3_verify_mandatory($params, NULL, array(
+      'start_date',
+      'title',
+      array('event_type_id', 'template_id'),
+    ));
+  }
+  // Required fields for creating an event template
+  elseif (empty($params['id']) && !empty($params['is_template'])) {
+    civicrm_api3_verify_mandatory($params, NULL, array(
+      'template_title',
+    ));
+  }
 
   // Clone event from template
   if (!empty($params['template_id']) && empty($params['id'])) {
@@ -64,8 +77,6 @@ function civicrm_api3_event_create($params) {
  *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_event_create_spec(&$params) {
-  $params['start_date']['api.required'] = 1;
-  $params['title']['api.required'] = 1;
   $params['is_active']['api.default'] = 1;
   $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
   $params['is_template']['api.default'] = 0;
index b672d56c3479f8eead4568e063402b0e1dc51fc6..a024995d8b9363a2c4d61c3126a628f22873c10b 100644 (file)
@@ -532,7 +532,7 @@ class api_v3_EventTest extends CiviUnitTestCase {
     $description = "Demonstrate use of getfields to interrogate api.";
     $params = array('action' => 'create');
     $result = $this->callAPISuccess('event', 'getfields', $params);
-    $this->assertEquals(1, $result['values']['title']['api.required']);
+    $this->assertEquals(1, $result['values']['is_active']['api.default']);
   }
 
   /**
@@ -542,7 +542,7 @@ class api_v3_EventTest extends CiviUnitTestCase {
     $description = "Demonstrate use of getfields to interrogate api.";
     $params = array('api_action' => 'create');
     $result = $this->callAPISuccess('event', 'getfields', $params);
-    $this->assertEquals(1, $result['values']['title']['api.required']);
+    $this->assertEquals(1, $result['values']['is_active']['api.default']);
   }
 
   public function testgetfieldsGet() {