/** * Delegated implementation of hook_civicrm_postProcess * * Handles the "Use Slider Widget?" field added to the custom fields UI */ function _volunteer_civicrm_postProcess_CRM_Custom_Form_Field($formName, &$form) { $is_slider_widget = CRM_Utils_Array::value('is_slider_widget', $form->_submitValues); $custom_field_id = $form->getVar('_id'); $verb = $is_slider_widget ? CRM_Core_Action::ADD : CRM_Core_Action::DELETE; _volunteer_update_slider_fields(array($verb => $custom_field_id)); }
/** * @param int $customGroupID The group to which the field should be added * @throws CRM_Core_Exception */ public function createVolunteerContactCustomFields($customGroupID) { if (!is_int($customGroupID)) { throw new CRM_Core_Exception('Non-numeric custom group ID provided.'); } // The code below is preferable, but it's blocked by CRM-15542. // $check = civicrm_api3('OptionGroup', 'get', array( // 'name' => self::skillLevelOptionGroupName, // )); // // // don't create the optionGroup (or the options) if an optionGroup with the same name already exists // if ($check['count'] === 0) { // $values = array( // 1 => ts('Not interested', array('domain' => 'org.civicrm.volunteer')), // 2 => ts('Teach me', array('domain' => 'org.civicrm.volunteer')), // 3 => ts('Apprentice', array('domain' => 'org.civicrm.volunteer')), // 4 => ts('Journeyman', array('domain' => 'org.civicrm.volunteer')), // 5 => ts('Master', array('domain' => 'org.civicrm.volunteer')), // ); // // $og = civicrm_api3('OptionGroup', 'create', array( // 'is_active' => 1, // 'name' => self::skillLevelOptionGroupName, // 'title' => ts('Skill Level', array('domain' => 'org.civicrm.volunteer')), // )); // // $weight = 1; // foreach ($values as $k => $v) { // civicrm_api3('OptionValue', 'create', array( // 'is_active' => 1, // 'label' => $v, // 'option_group_id' => $og['id'], // 'value' => $k, // 'weight' => $weight++, // )); // } // } $create = civicrm_api3('customField', 'create', array('custom_group_id' => $customGroupID, 'data_type' => 'String', 'html_type' => 'Multi-select', 'is_searchable' => 1, 'label' => ts('Camera Skill Level', array('domain' => 'org.civicrm.volunteer')), 'name' => 'camera_skill_level', 'option_values' => array(5 => array('is_active' => 1, 'label' => ts('Master', array('domain' => 'org.civicrm.volunteer')), 'value' => 5, 'weight' => 5), 4 => array('is_active' => 1, 'label' => ts('Journeyman', array('domain' => 'org.civicrm.volunteer')), 'value' => 4, 'weight' => 4), 3 => array('is_active' => 1, 'label' => ts('Apprentice', array('domain' => 'org.civicrm.volunteer')), 'value' => 3, 'weight' => 3), 2 => array('is_active' => 1, 'label' => ts('Teach me', array('domain' => 'org.civicrm.volunteer')), 'value' => 2, 'weight' => 2), 1 => array('is_active' => 1, 'label' => ts('Not interested', array('domain' => 'org.civicrm.volunteer')), 'value' => 1, 'weight' => 1)))); // hack for CRM-15542 - The custom field create API doesn't allow an existing option // group to specified; the options must be created with the field. We want to give // this option group a meaningful name and label so it's obvious it's intended to be // reused, so we rename it below. civicrm_api3('OptionGroup', 'create', array('id' => $create['values'][$create['id']]['option_group_id'], 'is_active' => 1, 'name' => self::skillLevelOptionGroupName, 'title' => ts('Skill Level', array('domain' => 'org.civicrm.volunteer')))); // end hack for CRM-15542 _volunteer_update_slider_fields(array(CRM_Core_Action::ADD => $create['id'])); $this->fieldCreateCheckForError($create); }
/** * @param int $customGroupID The group to which the field should be added * @throws CRM_Core_Exception */ public function createVolunteerContactCustomFields($customGroupID) { if (!is_int($customGroupID)) { throw new CRM_Core_Exception('Non-numeric custom group ID provided.'); } $skillLevelOptionGroup = $this->createPossibleDuplicateRecord('OptionGroup', array('is_active' => 1, 'name' => self::skillLevelOptionGroupName, 'title' => ts('Skill Level', array('domain' => 'org.civicrm.volunteer')))); $skillLevelOptionGroupId = CRM_Utils_Array::value('id', $skillLevelOptionGroup); // option group ID needs to be fetched if creation attempt was a duplicate if (!$skillLevelOptionGroupId) { $skillLevelOptionGroupId = civicrm_api3('OptionGroup', 'getvalue', array('name' => self::skillLevelOptionGroupName, 'return' => 'id')); } $values = array(1 => ts('Not interested', array('domain' => 'org.civicrm.volunteer')), 2 => ts('Teach me', array('domain' => 'org.civicrm.volunteer')), 3 => ts('Apprentice', array('domain' => 'org.civicrm.volunteer')), 4 => ts('Journeyman', array('domain' => 'org.civicrm.volunteer')), 5 => ts('Master', array('domain' => 'org.civicrm.volunteer'))); $weight = 1; foreach ($values as $k => $v) { civicrm_api3('OptionValue', 'create', array('is_active' => 1, 'label' => $v, 'option_group_id' => $skillLevelOptionGroupId, 'value' => $k, 'weight' => $weight++)); } $customField = $this->createPossibleDuplicateRecord('customField', array('custom_group_id' => $customGroupID, 'data_type' => 'String', 'html_type' => 'Multi-Select', 'is_searchable' => 1, 'label' => ts('Camera Skill Level', array('domain' => 'org.civicrm.volunteer')), 'name' => 'camera_skill_level', 'option_group_id' => $skillLevelOptionGroupId)); $customFieldId = CRM_Utils_Array::value('id', $customField); // custom field ID needs to be fetched if creation attempt was a duplicate if (!$customFieldId) { $customFieldId = civicrm_api3('customField', 'getvalue', array('custom_group_id' => $customGroupID, 'name' => 'camera_skill_level', 'return' => 'id')); } _volunteer_update_slider_fields(array(CRM_Core_Action::ADD => $customFieldId)); }