_groupId = $this->get('groupId'); $this->_fieldId = $this->get('fieldId'); if ($this->_fieldId) { // field preview $defaults = array(); $params = array('id' => $this->_fieldId); $fieldDAO = new CRM_Core_DAO_CustomField(); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults); if (!empty($defaults['is_view'])) { CRM_Core_Error::statusBounce(ts('This field is view only so it will not display on edit form.')); } elseif (CRM_Utils_Array::value('is_active', $defaults) == 0) { CRM_Core_Error::statusBounce(ts('This field is inactive so it will not display on edit form.')); } $groupTree = array(); $groupTree[$this->_groupId]['id'] = 0; $groupTree[$this->_groupId]['fields'] = array(); $groupTree[$this->_groupId]['fields'][$this->_fieldId] = $defaults; $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this); $this->assign('preview_type', 'field'); } else { $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($this->_groupId); $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, TRUE, $this); $this->assign('preview_type', 'group'); } } /** * Set the default form values. * * @return array * the default array reference */ public function setDefaultValues() { $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, FALSE, FALSE); return $defaults; } /** * Build the form object. * * @return void */ public function buildQuickForm() { if (is_array($this->_groupTree[$this->_groupId])) { foreach ($this->_groupTree[$this->_groupId]['fields'] as & $field) { //add the form elements CRM_Core_BAO_CustomField::addQuickFormElement($this, $field['element_name'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field)); } $this->assign('groupTree', $this->_groupTree); } $this->addButtons(array( array( 'type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => TRUE, ), ) ); } }