function buildQuickForm(&$form) { // call to build contact autocomplete $attributes = array('width' => '200px'); $form->add('text', "contact", ts('Select Contact'), $attributes); $form->addElement('hidden', "contact_select_id"); if (CRM_Core_Permission::check('edit all contacts') || CRM_Core_Permission::check('add contacts')) { // build select for new contact require_once 'CRM/Core/BAO/UFGroup.php'; $contactProfiles = CRM_Core_BAO_UFGroup::getReservedProfiles(); $form->add('select', 'profiles', ts('Create New Contact'), array('' => ts('- create new contact -')) + $contactProfiles, false, array('onChange' => "if (this.value) newContact( this.value );")); } }
/** * Function used to build form element for new contact or select contact widget * * @param object $form form object * @param int $blocNo by default it is one, except for address block where it is * build for each block * @param array $extrProfiles extra profiles that should be included besides reserved * * @access public * * @return void */ static function buildQuickForm(&$form, $blockNo = 1, $extraProfiles = NULL, $required = FALSE, $prefix = '') { // call to build contact autocomplete $attributes = array('width' => '200px'); $form->add('text', "{$prefix}contact[{$blockNo}]", ts('Select Contact'), $attributes, $required); $form->addElement('hidden', "{$prefix}contact_select_id[{$blockNo}]"); if (CRM_Core_Permission::check('edit all contacts') || CRM_Core_Permission::check('add contacts')) { // build select for new contact $contactProfiles = CRM_Core_BAO_UFGroup::getReservedProfiles('Contact', $extraProfiles); $form->add('select', "{$prefix}profiles[{$blockNo}]", ts('Create New Contact'), array('' => ts('- create new contact -')) + $contactProfiles, FALSE, array('onChange' => "if (this.value) { newContact{$prefix}{$blockNo}( this.value, {$blockNo}, '{$prefix}' );}")); } $form->assign('blockNo', $blockNo); $form->assign('prefix', $prefix); }
static function getValidContactTypeList($relType) { // string looks like 4_a_b $rel_parts = explode('_', $relType); $allRelationshipType = CRM_Core_PseudoConstant::relationshipType('label'); $contactProfiles = CRM_Core_BAO_UFGroup::getReservedProfiles('Contact', NULL); if ($rel_parts[1] == 'a') { $leftType = $allRelationshipType[$rel_parts[0]]['contact_type_b']; } else { $leftType = $allRelationshipType[$rel_parts[0]]['contact_type_a']; } // Handle 'All Contacts' contact type for left side of relationship ($leftType is empty in this case) // In this case all reserved profiles are available if ($leftType == '') { $contactTypes = $contactProfiles; } else { $contactTypes = array(); foreach ($contactProfiles as $key => $value) { $groupTypes = CRM_Core_BAO_UFGroup::profileGroups($key); if (in_array($leftType, $groupTypes)) { $contactTypes = array($key => $value); } } } return $contactTypes; }
static function getValidContactTypeList($relType) { // string looks like 4_a_b $rel_parts = explode('_', $relType); $allRelationshipType = CRM_Core_PseudoConstant::relationshipType('label'); $contactProfiles = CRM_Core_BAO_UFGroup::getReservedProfiles('Contact', NULL); if ($rel_parts[1] == 'a') { $leftType = $allRelationshipType[$rel_parts[0]]['contact_type_b']; } else { $leftType = $allRelationshipType[$rel_parts[0]]['contact_type_a']; } $contactTypes = array(); foreach ($contactProfiles as $key => $value) { if (strpos($value, $leftType) !== FALSE) { $contactTypes = array($key => $value); } } return $contactTypes; }