projects
/
civicrm-core.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #6574 from eileenmcnaughton/CRM-17070
[civicrm-core.git]
/
api
/
v3
/
CustomField.php
diff --git
a/api/v3/CustomField.php
b/api/v3/CustomField.php
index 3a73c916d3e89531b27be684c78302de77f57431..2cea880732ab606f03fbd7a5d59564cd27d6a33c 100644
(file)
--- a/
api/v3/CustomField.php
+++ b/
api/v3/CustomField.php
@@
-1,10
+1,9
@@
<?php
<?php
-
/*
+--------------------------------------------------------------------+
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.
6
|
+ | CiviCRM version 4.
7
|
+--------------------------------------------------------------------+
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-201
4
|
+ | Copyright CiviCRM LLC (c) 2004-201
5
|
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
@@
-27,39
+26,40
@@
*/
/**
*/
/**
- *
File for the CiviCRM APIv3 custom group functions
+ *
This api exposes CiviCRM custom field.
*
* @package CiviCRM_APIv3
*
* @package CiviCRM_APIv3
- * @subpackage API_CustomField
- *
- * @copyright CiviCRM LLC (c) 2004-2014
- * @version $Id: CustomField.php 30879 2010-11-22 15:45:55Z shot $
*/
/**
* Create a 'custom field' within a custom field group.
*/
/**
* Create a 'custom field' within a custom field group.
+ *
* We also empty the static var in the getfields
* function after deletion so that the field is available for us (getfields manages date conversion
* among other things
*
* We also empty the static var in the getfields
* function after deletion so that the field is available for us (getfields manages date conversion
* among other things
*
- * @param $params
- * Array
Associative array of property name/value pairs to create new custom field
.
+ * @param
array
$params
+ * Array
per getfields metadata
.
*
* @return array
* API success array
*
* @return array
* API success array
- *
- * @access public
- *
- * @example CustomFieldCreate.php
- * {@getfields CustomField_create}
- * {@example CustomFieldCreate.php 0}
- *
*/
function civicrm_api3_custom_field_create($params) {
*/
function civicrm_api3_custom_field_create($params) {
- // Array created for passing options in params
+ // Array created for passing options in params
.
if (isset($params['option_values']) && is_array($params['option_values'])) {
if (isset($params['option_values']) && is_array($params['option_values'])) {
+ $weight = 0;
foreach ($params['option_values'] as $key => $value) {
foreach ($params['option_values'] as $key => $value) {
+ // Translate simple key/value pairs into full-blown option values
+ if (!is_array($value)) {
+ $value = array(
+ 'label' => $value,
+ 'value' => $key,
+ 'is_active' => 1,
+ 'weight' => $weight,
+ );
+ $key = $weight++;
+ }
$params['option_label'][$key] = $value['label'];
$params['option_value'][$key] = $value['value'];
$params['option_status'][$key] = $value['is_active'];
$params['option_label'][$key] = $value['label'];
$params['option_value'][$key] = $value['value'];
$params['option_status'][$key] = $value['is_active'];
@@
-70,29
+70,35
@@
function civicrm_api3_custom_field_create($params) {
$customField = CRM_Core_BAO_CustomField::create($params);
_civicrm_api3_object_to_array_unique_fields($customField, $values[$customField->id]);
_civicrm_api3_custom_field_flush_static_caches();
$customField = CRM_Core_BAO_CustomField::create($params);
_civicrm_api3_object_to_array_unique_fields($customField, $values[$customField->id]);
_civicrm_api3_custom_field_flush_static_caches();
- return civicrm_api3_create_success($values, $params, '
custom_f
ield', $customField);
+ return civicrm_api3_create_success($values, $params, '
CustomF
ield', $customField);
}
/**
}
/**
- * Flush static caches in functions that might have stored available custom fields
+ * Flush static caches in functions that might have stored available custom fields
.
*/
function _civicrm_api3_custom_field_flush_static_caches() {
*/
function _civicrm_api3_custom_field_flush_static_caches() {
- civicrm_api('
custom_f
ield', 'getfields', array('version' => 3, 'cache_clear' => 1));
+ civicrm_api('
CustomF
ield', 'getfields', array('version' => 3, 'cache_clear' => 1));
CRM_Core_BAO_UFField::getAvailableFieldsFlat(TRUE);
}
/**
CRM_Core_BAO_UFField::getAvailableFieldsFlat(TRUE);
}
/**
- * Adjust Metadata for Create action
+ * Adjust Metadata for Create action
.
*
* @param array $params
*
* @param array $params
- * Array o
r
parameters determined by getfields.
+ * Array o
f
parameters determined by getfields.
*/
function _civicrm_api3_custom_field_create_spec(&$params) {
$params['label']['api.required'] = 1;
$params['custom_group_id']['api.required'] = 1;
$params['is_active']['api.default'] = 1;
*/
function _civicrm_api3_custom_field_create_spec(&$params) {
$params['label']['api.required'] = 1;
$params['custom_group_id']['api.required'] = 1;
$params['is_active']['api.default'] = 1;
+ $params['option_values'] = array(
+ 'title' => 'Option Values',
+ 'description' => "Pass an array of options (value => label) to create this field's option values",
+ );
+ // TODO: Why expose this to the api at all?
$params['option_type'] = array(
$params['option_type'] = array(
- 'title' => 'This (boolean) field tells the BAO to create an option group for the field if the field type is appropriate',
+ 'title' => 'Option Type',
+ 'description' => 'This (boolean) field tells the BAO to create an option group for the field if the field type is appropriate',
'api.default' => 1,
'type' => CRM_Utils_Type::T_BOOLEAN,
);
'api.default' => 1,
'type' => CRM_Utils_Type::T_BOOLEAN,
);
@@
-101,24
+107,19
@@
function _civicrm_api3_custom_field_create_spec(&$params) {
}
/**
}
/**
- * Use this API to delete an existing custom
group
field.
+ * Use this API to delete an existing custom field.
*
*
- * @param $params
+ * @param
array
$params
* Array id of the field to be deleted.
*
* @return array
* Array id of the field to be deleted.
*
* @return array
- * @example CustomFieldDelete.php
- *
- * {@example CustomFieldDelete.php 0}
- * {@getfields CustomField_delete}
- * @access public
- **/
+ */
function civicrm_api3_custom_field_delete($params) {
$field = new CRM_Core_BAO_CustomField();
$field->id = $params['id'];
$field->find(TRUE);
$customFieldDelete = CRM_Core_BAO_CustomField::deleteField($field);
function civicrm_api3_custom_field_delete($params) {
$field = new CRM_Core_BAO_CustomField();
$field->id = $params['id'];
$field->find(TRUE);
$customFieldDelete = CRM_Core_BAO_CustomField::deleteField($field);
- civicrm_api('
custom_f
ield', 'getfields', array('version' => 3, 'cache_clear' => 1));
+ civicrm_api('
CustomF
ield', 'getfields', array('version' => 3, 'cache_clear' => 1));
return $customFieldDelete ? civicrm_api3_create_error('Error while deleting custom field') : civicrm_api3_create_success();
}
return $customFieldDelete ? civicrm_api3_create_error('Error while deleting custom field') : civicrm_api3_create_success();
}
@@
-129,16
+130,14
@@
function civicrm_api3_custom_field_delete($params) {
* Array to search on.
*
* @return array
* Array to search on.
*
* @return array
- * @getfields CustomField_get
- * @access public
- *
- **/
+ */
function civicrm_api3_custom_field_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
/**
function civicrm_api3_custom_field_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
/**
- * Helper function to validate custom field value
+ * Helper function to validate custom field value.
+ *
* @deprecated
*
* @param string $fieldName
* @deprecated
*
* @param string $fieldName
@@
-150,13
+149,13
@@
function civicrm_api3_custom_field_get($params) {
* @param array $errors
* Collect validation errors.
*
* @param array $errors
* Collect validation errors.
*
- * @return array
+ * @return array
|NULL
* Validation errors
* @todo remove this function - not in use but need to review functionality before
* removing as it might be useful in wrapper layer
*/
function _civicrm_api3_custom_field_validate_field($fieldName, $value, $fieldDetails, &$errors = array()) {
* Validation errors
* @todo remove this function - not in use but need to review functionality before
* removing as it might be useful in wrapper layer
*/
function _civicrm_api3_custom_field_validate_field($fieldName, $value, $fieldDetails, &$errors = array()) {
- return;
+ return
NULL
;
//see comment block
if (!$value) {
return $errors;
//see comment block
if (!$value) {
return $errors;
@@
-262,11
+261,16
@@
SELECT count(*)
}
/**
}
/**
- * CRM-15191 - Hack to ensure the cache gets cleared after updating a custom field
+ * CRM-15191 - Hack to ensure the cache gets cleared after updating a custom field.
+ *
+ * @param array $params
+ * Array per getfields metadata.
+ *
+ * @return array
*/
function civicrm_api3_custom_field_setvalue($params) {
require_once 'api/v3/Generic/Setvalue.php';
*/
function civicrm_api3_custom_field_setvalue($params) {
require_once 'api/v3/Generic/Setvalue.php';
- $result = civicrm_api3_generic_setValue(array("entity" => '
custom_f
ield', 'params' => $params));
+ $result = civicrm_api3_generic_setValue(array("entity" => '
CustomF
ield', 'params' => $params));
if (empty($result['is_error'])) {
CRM_Utils_System::flushCache();
}
if (empty($result['is_error'])) {
CRM_Utils_System::flushCache();
}