/** * When omitting a GID, return a list of all fields. */ public function testGetAvailable_full() { $fields = CRM_Core_BAO_UFField::getAvailableFields(); // Make sure that each entity appears with at least one field $this->assertEquals('do_not_sms', $fields['Contact']['do_not_sms']['name']); $this->assertEquals('city', $fields['Contact']['city']['name']); $this->assertEquals('first_name', $fields['Individual']['first_name']['name']); $this->assertEquals('birth_date', $fields['Individual']['birth_date']['name']); $this->assertEquals('organization_name', $fields['Organization']['organization_name']['name']); $this->assertEquals('legal_name', $fields['Organization']['legal_name']['name']); $this->assertEquals('amount_level', $fields['Contribution']['amount_level']['name']); $this->assertEquals('cancel_reason', $fields['Contribution']['cancel_reason']['name']); $this->assertEquals('participant_note', $fields['Participant']['participant_note']['name']); $this->assertEquals('participant_role', $fields['Participant']['participant_role']['name']); $this->assertEquals('join_date', $fields['Membership']['join_date']['name']); $this->assertEquals('end_date', $fields['Membership']['membership_end_date']['name']); $this->assertEquals('activity_date_time', $fields['Activity']['activity_date_time']['name']); $this->assertEquals('subject', $fields['Activity']['activity_subject']['name']); // Make sure that some of the blacklisted fields don't appear $this->assertFalse(isset($fields['Contribution']['is_pay_later'])); $this->assertFalse(isset($fields['Participant']['participant_role_id'])); $this->assertFalse(isset($fields['Membership']['membership_type_id'])); // This behavior is not necessarily desirable, but it's the status quo $this->assertEquals('first_name', $fields['Staff']['first_name']['name']); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_UFField::retrieve($params, $defaults); // set it to null if so (avoids crappy E_NOTICE errors below $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults); $specialFields = CRM_Core_BAO_UFGroup::getLocationFields(); if (!$defaults['location_type_id'] && $defaults["field_type"] != "Formatting" && in_array($defaults['field_name'], $specialFields)) { $defaults['location_type_id'] = 0; } $defaults['field_name'] = array($defaults['field_type'], $defaults['field_type'] == "Formatting" ? "" : $defaults['field_name'], $defaults['field_name'] == "url" ? $defaults['website_type_id'] : $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults)); $this->_gid = $defaults['uf_group_id']; } else { $defaults['is_active'] = 1; } $otherModules = array_values(CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid)); $this->assign('otherModules', $otherModules); if ($this->_action & CRM_Core_Action::ADD) { $fieldValues = array('uf_group_id' => $this->_gid); $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues); } // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); //hidden field to catch the group id in profile $this->add('hidden', 'group_id', $this->_gid); //hidden field to catch the field id in profile $this->add('hidden', 'field_id', $this->_id); $fields = CRM_Core_BAO_UFField::getAvailableFields($this->_gid, $defaults); $noSearchable = $hasWebsiteTypes = array(); $addressCustomFields = array_keys(CRM_Core_BAO_CustomField::getFieldsForImport('Address')); foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { //CRM-2676, replacing the conflict for same custom field name from different custom group. if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) { $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id'); $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title'); $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName; if (in_array($key1, $addressCustomFields)) { $noSearchable[] = $value1['title'] . ' :: ' . $customGroupName; } } else { $this->_mapperFields[$key][$key1] = $value1['title']; } $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1); $hasWebsiteTypes[$key][$key1] = CRM_Utils_Array::value('hasWebsiteType', $value1); // hide the 'is searchable' field for 'File' custom data if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) { if (!in_array($value1['title'], $noSearchable)) { $noSearchable[] = $value1['title']; } } } } $this->assign('noSearchable', $noSearchable); $this->_location_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); $this->_website_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); /** * FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $this->_location_types[$defaultLocationType->id]; unset($this->_location_types[$defaultLocationType->id]); $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types; } $this->_location_types = array('Primary') + $this->_location_types; // since we need a hierarchical list to display contact types & subtypes, // this is what we going to display in first selector $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE); unset($contactTypes['']); $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array(); $sel1 = array('' => '- select -') + $contactTypes; if (!empty($fields['Activity'])) { $sel1['Activity'] = 'Activity'; } if (CRM_Core_Permission::access('CiviEvent')) { $sel1['Participant'] = 'Participants'; } if (!empty($fields['Contribution'])) { $sel1['Contribution'] = 'Contributions'; } if (!empty($fields['Membership'])) { $sel1['Membership'] = 'Membership'; } if (!empty($fields['Case'])) { $sel1['Case'] = 'Case'; } if (!empty($fields['Formatting'])) { $sel1['Formatting'] = 'Formatting'; } foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $this->_mapperFields[$key]; } } $sel3[''] = NULL; $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); ksort($phoneTypes); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_location_types as $key => $value) { $sel4[$k]['phone'][$key] =& $phoneTypes; $sel4[$k]['phone_and_ext'][$key] =& $phoneTypes; } } } foreach ($sel1 as $k => $sel) { if ($k) { if (is_array($this->_mapperFields[$k])) { foreach ($this->_mapperFields[$k] as $key => $value) { if ($hasLocationTypes[$k][$key]) { $sel3[$k][$key] = $this->_location_types; } elseif ($hasWebsiteTypes[$k][$key]) { $sel3[$k][$key] = $this->_website_types; } else { $sel3[$key] = NULL; } } } } } $this->_defaults = array(); $js = "<script type='text/javascript'>\n"; $formName = "document.{$this->_name}"; $alreadyMixProfile = FALSE; if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { $alreadyMixProfile = TRUE; } $this->assign('alreadyMixProfile', $alreadyMixProfile); $sel =& $this->addElement('hierselect', 'field_name', ts('Field Name')); $formValues = $this->exportValues(); if (empty($formValues)) { for ($k = 1; $k < 4; $k++) { if (!isset($defaults['field_name'][$k])) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } else { if (!empty($formValues['field_name'])) { for ($key = 1; $key < 4; $key++) { if (!isset($formValues['field_name'][$key])) { $js .= "{$formName}['field_name[{$key}]'].style.display = 'none';\n"; } else { $js .= "{$formName}['field_name[{$key}]'].style.display = '';\n"; } } } else { for ($k = 1; $k < 4; $k++) { if (!isset($defaults['field_name'][$k])) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } } foreach ($sel2 as $k => $v) { if (is_array($sel2[$k])) { asort($sel2[$k]); } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); // proper interpretation of spec in CRM-8732 if (!isset($this->_id) && in_array('Search Profile', $otherModules)) { $defaults['visibility'] = 'Public Pages and Listings'; } $js .= "</script>\n"; $this->assign('initHideBoxes', $js); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), TRUE, array('onChange' => "showHideSeletorSearch(this.value);")); //CRM-4363 $js = array('onChange' => "mixProfile();"); // should the field appear in selectors (as a column)? $this->add('checkbox', 'in_selector', ts('Results Column?'), NULL, NULL, $js); $this->add('checkbox', 'is_searchable', ts('Searchable?'), NULL, NULL, $js); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField'); // weight $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE); $this->addRule('weight', ts('is a numeric field'), 'numeric'); $this->add('textarea', 'help_pre', ts('Field Pre Help'), $attributes['help_pre']); $this->add('textarea', 'help_post', ts('Field Post Help'), $attributes['help_post']); $this->add('checkbox', 'is_required', ts('Required?')); $this->add('checkbox', 'is_multi_summary', ts('Include in multi-record listing?')); $this->add('checkbox', 'is_active', ts('Active?')); $this->add('checkbox', 'is_view', ts('View Only?')); // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) ); //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) ); $this->add('text', 'label', ts('Field Label'), $attributes['label']); $js = NULL; if ($this->_hasSearchableORInSelector) { $js = array('onclick' => "return verify( );"); } // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'")); } $this->setDefaults($defaults); }