3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | This file is a part of CiviCRM. |
8 | CiviCRM is free software; you can copy, modify, and distribute it |
9 | under the terms of the GNU Affero General Public License |
10 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | CiviCRM is distributed in the hope that it will be useful, but |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15 | See the GNU Affero General Public License for more details. |
17 | You should have received a copy of the GNU Affero General Public |
18 | License and the CiviCRM Licensing Exception along |
19 | with this program; if not, contact CiviCRM LLC |
20 | at info[AT]civicrm[DOT]org. If you have questions about the |
21 | GNU Affero General Public License or the licensing of CiviCRM, |
22 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
23 +--------------------------------------------------------------------+
27 * Field handler to render a custom field with options
29 * @ingroup civicrm_field_handlers
31 class civicrm_handler_field_custom extends views_handler_field {
32 function construct() {
37 function option_definition() {
38 $options = parent::option_definition();
39 $options['civicrm_custom_formatter'] = array(
45 function options_form(&$form, &$form_state) {
46 parent::options_form($form, $form_state);
47 // Replicate Drupal UI for formatter options, but with CiviCRM
49 $form['civicrm_custom_formatter'] = array(
50 '#title' => 'Formatter',
52 '#default_value' => $this->options['civicrm_custom_formatter'],
54 'label' => t('Label'),
55 'value' => t('Value'),
60 function render($values) {
61 $value = $values->{$this->field_alias};
62 switch ($this->options['civicrm_custom_formatter']) {
64 $value = trim($value, CRM_Core_DAO::VALUE_SEPARATOR);
65 $value = implode(', ', explode(CRM_Core_DAO::VALUE_SEPARATOR, $value));
70 if (!is_null($value)) {
71 // get the field id from the db
72 if (!empty($this->definition['title'])) {
73 $customFieldID = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_CustomField', $this->definition['title'], 'id', 'label');
74 require_once 'CRM/Core/BAO/CustomOption.php';
75 return CRM_Core_BAO_CustomOption::getOptionLabel($customFieldID, $value);
77 // could not get custom id, lets just return what we have