*
* @return array
* API result array.
+ *
+ * @throws \API_Exception
*/
function civicrm_api3_loc_block_create($params) {
$entities = array();
+ civicrm_api3_verify_one_mandatory($params, NULL, array('address', 'phone', 'im', 'email'));
// Call the appropriate api to create entities if any are passed in the params
// This is basically chaining but in reverse - we create the sub-entities first
// This exists because chainging does not work in reverse, or with keys like 'email_2'
}
// Bother calling the api
else {
- $info['version'] = $params['version'];
$info['contact_id'] = CRM_Utils_Array::value('contact_id', $info, 'null');
- $result = civicrm_api($item, 'create', $info);
- if (!empty($result['is_error'])) {
- return $result;
- }
+ $result = civicrm_api3($item, 'create', $info);
$entities[$key] = $result['values'][$result['id']];
$params[$key . '_id'] = $result['id'];
}
_civicrm_api3_object_to_array($dao, $values[$dao->id]);
return civicrm_api3_create_success($values, $params, 'LocBlock', 'create', $dao);
}
- return civicrm_api3_create_error('Unable to create LocBlock. Please check your params.');
+ throw New API_Exception('Unable to create LocBlock. Please check your params.');
}
/**
*/
function _civicrm_api3_mailing_component_create_spec(&$spec) {
$spec['is_active']['api.default'] = 1;
+ $spec['name']['api.required'] = 1;
+ $spec['component_type']['api.required'] = 1;
}
/**
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
+/**
+ * Adjust Metadata for Create action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $spec
+ * Array of parameters determined by getfields.
+ */
+function _civicrm_api3_mapping_create_spec(&$spec) {
+ $spec['name']['api.required'] = 1;
+}
+
/**
* Deletes an existing Mapping.
*
* @param array $params
*/
function _civicrm_api3_navigation_create_spec(&$params) {
+ $params['name']['api.required'] = 1;
}
/**
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
+/**
+ * Adjust metadata for navigation create action.
+ *
+ * @param array $params
+ */
+function _civicrm_api3_print_label_create_spec(&$params) {
+ $params['name']['api.required'] = 1;
+}
+
/**
* Get a PrintLabel.
*
'civicrm_event' => 'civicrm_event',
'civicrm_activity' => 'civicrm_activity',
);
+ $params['entity_table']['api.required'] = 1;
}
/**
* @access public
*/
function civicrm_api3_saved_search_create($params) {
+ civicrm_api3_verify_one_mandatory($params, NULL, array('form_values', 'where_clause'));
// The create function of the dao expects a 'formValues' that is
// not serialized. The get function returns form_values, that is
// serialized.
* @throws \API_Exception
*/
function civicrm_api3_word_replacement_get($params) {
- // NEVER COPY THIS. No idea why a newish api would not use basic_get.
- $bao = new CRM_Core_BAO_WordReplacement();
- _civicrm_api3_dao_set_filter($bao, $params, TRUE);
- $wordReplacements = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'WordReplacement');
-
- return civicrm_api3_create_success($wordReplacements, $params, 'WordReplacement', 'get', $bao);
+ return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
* Array of parameters determined by getfields.
*/
function _civicrm_api3_word_replacement_create_spec(&$params) {
- unset($params['version']);
+ $params['find_word']['api.required'] = 1;
+ $params['replace_word']['api.required'] = 1;
+ $params['is_active']['api.default'] = 1;
}
/**
* @param $Entity
*/
public function testWithoutParam_create($Entity) {
- // should create php complaining that a param is missing
- $result = civicrm_api3($Entity, 'Create');
- }
-
- /**
- * @dataProvider entities_create
- * @param $Entity
- * @throws \PHPUnit_Framework_IncompleteTestError
- */
- public function testEmptyParam_create($Entity) {
- $this->markTestIncomplete("fixing this test to test the api functions fails on numerous tests
- which will either create a completely blank entity (batch, participant status) or
- have a damn good crack at it (e.g mailing job). Marking this as incomplete beats false success");
- return;
- if (in_array($Entity, $this->toBeImplemented['create'])) {
- // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
- return;
+ if ($Entity === 'Setting') {
+ $this->markTestSkipped('It seems OK for setting to skip here as it silently sips invalid params');
}
- $result = $this->callAPIFailure($Entity, 'Create', array());
- $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']);
+ // should create php complaining that a param is missing
+ civicrm_api3($Entity, 'Create');
}
/**