_type = $type; } else { $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form); } if (isset($subType)) { $form->_subType = $subType; } else { $form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form); } if ($form->_subType == 'null') { $form->_subType = NULL; } if (isset($subName)) { $form->_subName = $subName; } else { $form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form); } if ($form->_subName == 'null') { $form->_subName = NULL; } if ($groupCount) { $form->_groupCount = $groupCount; } else { $form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form); } $form->assign('cgCount', $form->_groupCount); //carry qf key, since this form is not inhereting core form. if ($qfKey = CRM_Utils_Request::retrieve('qfKey', 'String')) { $form->assign('qfKey', $qfKey); } if ($entityID) { $form->_entityId = $entityID; } else { $form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form); } $typeCheck = CRM_Utils_Request::retrieve('type', 'String'); $urlGroupId = CRM_Utils_Request::retrieve('groupID', 'Positive'); if (isset($typeCheck) && $urlGroupId) { $form->_groupID = $urlGroupId; } else { $form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form); } $gid = (isset($form->_groupID)) ? $form->_groupID : NULL; $getCachedTree = isset($form->_getCachedTree) ? $form->_getCachedTree : TRUE; $subType = $form->_subType; if (!is_array($subType) && strstr($subType, CRM_Core_DAO::VALUE_SEPARATOR)) { $subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR)); } self::setGroupTree($form, $subType, $gid, $onlySubType, $getCachedTree); } /** * @param CRM_Core_Form $form * * @return array */ public static function setDefaultValues(&$form) { $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($form->_groupTree, $defaults, FALSE, FALSE, $form->get('action')); return $defaults; } /** * @param CRM_Core_Form $form */ public static function buildQuickForm(&$form) { $form->addElement('hidden', 'hidden_custom', 1); $form->addElement('hidden', "hidden_custom_group_count[{$form->_groupID}]", $form->_groupCount); CRM_Core_BAO_CustomGroup::buildQuickForm($form, $form->_groupTree); } /** * @param $form * @param $subType * @param $gid * @param $onlySubType * @param $getCachedTree * * @return array */ public static function setGroupTree(&$form, $subType, $gid, $onlySubType = NULL, $getCachedTree = FALSE) { $singleRecord = NULL; if (!empty($form->_groupCount) && !empty($form->_multiRecordDisplay) && $form->_multiRecordDisplay == 'single') { $singleRecord = $form->_groupCount; } $mode = CRM_Utils_Request::retrieve('mode', 'String', $form); // when a new record is being added for multivalued custom fields. if (isset($form->_groupCount) && $form->_groupCount == 0 && $mode == 'add' && !empty($form->_multiRecordDisplay) && $form->_multiRecordDisplay == 'single') { $singleRecord = 'new'; } $groupTree = CRM_Core_BAO_CustomGroup::getTree($form->_type, NULL, $form->_entityId, $gid, $subType, $form->_subName, $getCachedTree, $onlySubType, FALSE, TRUE, $singleRecord ); if (property_exists($form, '_customValueCount') && !empty($groupTree)) { $form->_customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, TRUE, NULL, NULL, NULL, $form->_entityId); } // we should use simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form); if (isset($form->_groupTree) && is_array($form->_groupTree)) { $keys = array_keys($groupTree); foreach ($keys as $key) { $form->_groupTree[$key] = $groupTree[$key]; } return array($form, $groupTree); } else { $form->_groupTree = $groupTree; return array($form, $groupTree); } } }