From 48ae8c9dcdf811197283ee7f8bdbfb363735d5b2 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 1 Aug 2015 22:50:55 -0400 Subject: [PATCH] CRM-14055 - Allow creating an event template via api --- api/v3/Event.php | 17 ++++++++++++++--- tests/phpunit/api/v3/EventTest.php | 4 ++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/api/v3/Event.php b/api/v3/Event.php index 4728270b45..b6c24ff5ee 100644 --- a/api/v3/Event.php +++ b/api/v3/Event.php @@ -42,7 +42,20 @@ * 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; diff --git a/tests/phpunit/api/v3/EventTest.php b/tests/phpunit/api/v3/EventTest.php index b672d56c34..a024995d8b 100644 --- a/tests/phpunit/api/v3/EventTest.php +++ b/tests/phpunit/api/v3/EventTest.php @@ -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() { -- 2.25.1