_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', FALSE); if ($this->_cdType) { $this->assign('cdType', TRUE); return CRM_Custom_Form_CustomData::preProcess($this); } $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE); $this->_tableID = CRM_Utils_Request::retrieve('tableId', 'Positive', $this, TRUE); $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID); $this->_contactSubType = CRM_Contact_BAO_Contact::getContactSubType($this->_tableID, ','); $this->assign('contact_type', $this->_contactType); $this->assign('contact_subtype', $this->_contactSubType); list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_tableID); CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName); // when custom data is included in this page if (CRM_Utils_Array::value('hidden_custom', $_POST)) { for ($i = 0; $i <= $_POST['hidden_custom_group_count'][$this->_groupID]; $i++) { CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, $i); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } } } /** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //need to assign custom data type and subtype to the template $this->assign('entityID', $this->_tableID); $this->assign('groupID', $this->_groupID); // make this form an upload since we dont know if the custom data injected dynamically // is of type file etc $this->addButtons(array( array( 'type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, ), array( 'type' => 'cancel', 'name' => ts('Cancel'), ), ) ); } /** * Set the default form values * * @access protected * * @return array the default array reference */ function setDefaultValues() { if ($this->_cdType) { $customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this); return $customDefaultValue; } $groupTree = &CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType ); if (!CRM_Utils_Array::value('hidden_custom_group_count', $_POST)) { // custom data building in edit mode (required to handle multi-value) $groupTree = &CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType ); $customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, TRUE, $this->_groupID); } else { $customValueCount = $_POST['hidden_custom_group_count'][$this->_groupID]; } $this->assign('customValueCount', $customValueCount); $defaults = array(); return $defaults; } /** * Process the user submitted custom data values. * * @access public * * @return void */ public function postProcess() { // Get the form values and groupTree $params = $this->controller->exportValues($this->_name); CRM_Core_BAO_CustomValueTable::postProcess($params, $this->_groupTree[$this->_groupID]['fields'], 'civicrm_contact', $this->_tableID, $this->_entityType ); // reset the group contact cache for this group CRM_Contact_BAO_GroupContactCache::remove(); } }