From: Coleman Watts Date: Mon, 9 Mar 2015 14:22:42 +0000 (-0400) Subject: CRM-16077 - Expose optionEditPath to api getfields X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=14f42e3182d0b110a68ebf23d9d187759583ddea;p=civicrm-core.git CRM-16077 - Expose optionEditPath to api getfields --- diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index b869dc34e7..b73b2d5114 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -509,10 +509,13 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $cfTable.option_group_id, $cfTable.date_format, $cfTable.time_format, - $cgTable.is_multiple + $cgTable.is_multiple, + og.name as option_group_name FROM $cfTable INNER JOIN $cgTable - ON $cfTable.custom_group_id = $cgTable.id + ON $cfTable.custom_group_id = $cgTable.id + LEFT JOIN civicrm_option_group og + ON $cfTable.option_group_id = og.id WHERE ( 1 ) "; if (!$showAll) { @@ -577,6 +580,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $fields[$dao->id]['date_format'] = $dao->date_format; $fields[$dao->id]['time_format'] = $dao->time_format; $fields[$dao->id]['is_required'] = $dao->is_required; + self::getOptionsForField($fields[$dao->id], $dao->option_group_name); } CRM_Core_BAO_Cache::setItem($fields, @@ -2532,4 +2536,37 @@ WHERE cf.id = %1 AND cg.is_multiple = 1"; return ($field['html_type'] == 'CheckBox' || strpos($field['html_type'], 'Multi') !== FALSE); } + /** + * @param array $field + * @param string|null $optionGroupName + */ + private static function getOptionsForField(&$field, $optionGroupName) { + if ($optionGroupName) { + $field['pseudoconstant'] = array( + 'optionGroupName' => $optionGroupName, + 'optionEditPath' => 'civicrm/admin/options/' . $optionGroupName, + ); + } + elseif ($field['data_type'] == 'Boolean') { + $field['pseudoconstant'] = array( + 'callback' => 'CRM_Core_SelectValues::boolean', + ); + } + elseif ($field['data_type'] == 'Country') { + $field['pseudoconstant'] = array( + 'table' => 'civicrm_country', + 'keyColumn' => 'id', + 'labelColumn' => 'name', + 'nameColumn' => 'iso_code', + ); + } + elseif ($field['data_type'] == 'StateProvince') { + $field['pseudoconstant'] = array( + 'table' => 'civicrm_state_province', + 'keyColumn' => 'id', + 'labelColumn' => 'name', + ); + } + } + } diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index a9063cb5fc..2e19753969 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -399,12 +399,17 @@ class CRM_Core_CodeGen_Specification { 'condition', // callback funtion incase of static arrays 'callback', + // Path to options edit form + 'optionEditPath', ); foreach ($validOptions as $pseudoOption) { if (!empty($fieldXML->pseudoconstant->$pseudoOption)) { $field['pseudoconstant'][$pseudoOption] = $this->value($pseudoOption, $fieldXML->pseudoconstant); } } + if (!isset($field['pseudoconstant']['optionEditPath']) && !empty($field['pseudoconstant']['optionGroupName'])) { + $field['pseudoconstant']['optionEditPath'] = 'civicrm/admin/options/' . $field['pseudoconstant']['optionGroupName']; + } // For now, fields that have option lists that are not in the db can simply // declare an empty pseudoconstant tag and we'll add this placeholder. // That field's BAO::buildOptions fn will need to be responsible for generating the option list diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index b5c9e5c2b9..9d9b480253 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -249,7 +249,7 @@ class CRM_Core_PseudoConstant { $options = $context == 'validate' ? self::countryIsoCode() : self::country(); } elseif ($customField->data_type === 'Boolean') { - $options = $context == 'validate' ? array(0, 1) : array(1 => ts('Yes'), 0 => ts('No')); + $options = $context == 'validate' ? array(0, 1) : CRM_Core_SelectValues::boolean(); } } CRM_Utils_Hook::customFieldOptions($customField->id, $options, FALSE); diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index fff91f8274..721ba43ea4 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -37,6 +37,18 @@ */ class CRM_Core_SelectValues { + /** + * Yes/No options + * + * @return array + */ + public static function boolean() { + return array( + 1 => ts('Yes'), + 0 => ts('No'), + ); + } + /** * Preferred mail format. * @@ -231,7 +243,6 @@ class CRM_Core_SelectValues { * Styles for displaying the custom data group. * * @return array - * */ public static function customGroupStyle() { return array( @@ -265,7 +276,6 @@ class CRM_Core_SelectValues { * The status of a contact within a group. * * @return array - * */ public static function groupContactStatus() { return array(