3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This api exposes CiviCRM email records.
15 * @package CiviCRM_APIv3
19 * Add an Email for a contact.
21 * @param array $params
22 * Array per getfields metadata.
27 * @throws \API_Exception
28 * @throws \Civi\API\Exception\UnauthorizedException
30 function civicrm_api3_email_create($params) {
31 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'Email');
35 * Adjust Metadata for Create action.
37 * The metadata is used for setting defaults, documentation & validation.
39 * @param array $params
40 * Array of parameters determined by getfields.
42 function _civicrm_api3_email_create_spec(&$params) {
43 $params['is_primary']['api.default'] = 0;
44 $params['email']['api.required'] = 1;
45 $params['contact_id']['api.required'] = 1;
46 $defaultLocation = CRM_Core_BAO_LocationType
::getDefault();
47 if ($defaultLocation) {
48 $params['location_type_id']['api.default'] = $defaultLocation->id
;
53 * Deletes an existing Email.
55 * @param array $params
56 * Array per getfields metadata.
61 * @throws \API_Exception
62 * @throws \CiviCRM_API3_Exception
63 * @throws \Civi\API\Exception\UnauthorizedException
65 function civicrm_api3_email_delete($params) {
66 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
70 * Retrieve one or more emails.
72 * @param array $params
73 * Array per getfields metadata.
78 function civicrm_api3_email_get($params) {
79 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
83 * Set default getlist parameters.
85 * @see _civicrm_api3_generic_getlist_defaults
87 * @param array $request
91 function _civicrm_api3_email_getlist_defaults(&$request) {
93 'description_field' => [
98 'contact_id.is_deleted' => 0,
99 'contact_id.is_deceased' => 0,
100 'contact_id.do_not_email' => 0,
102 // Note that changing this to display name affects query performance. The label field is used
103 // for sorting & mysql will prefer to use the index on the ORDER BY field. So if this is changed
104 // to display name then the filtering will bypass the index. In testing this took around 30 times
106 'label_field' => 'contact_id.sort_name',
107 // If no results from sort_name try email.
108 'search_field' => 'contact_id.sort_name',
109 'search_field_fallback' => 'email',