/** * Merges the fields together and stores them in $this->mergedFields * */ protected function mergeFields() { if ($this->sugarMerge instanceof SugarMerge && is_file($this->sugarMerge->getNewPath() . 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php')) { require_once $this->sugarMerge->getNewPath() . 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php'; } else { require_once 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php'; } $objectName = BeanFactory::getBeanName($this->module); VardefManager::loadVardef($this->module, $objectName); foreach ($this->customFields as $field => $data) { $fieldName = strtolower($data['loc']['row']); if (!empty($GLOBALS['dictionary'][$objectName]['fields'][$fieldName])) { $data['data'] = array_merge(ListLayoutMetaDataParser::createViewDefsByFieldDefs($GLOBALS['dictionary'][$objectName]['fields'][$fieldName]), $data['data']); } //if we have this field in both the new fields and the original fields - it has existed since the last install/upgrade if (isset($this->newFields[$field]) && isset($this->originalFields[$field])) { //if both the custom field and the original match then we take the location of the custom field since it hasn't moved $loc = $this->customFields[$field]['loc']; $loc['source'] = 'custom'; //echo var_export($loc, true); //but we still merge the meta data of the three $this->mergedFields[$field] = array('data' => $this->mergeField($this->originalFields[$field]['data'], $this->newFields[$field]['data'], $this->customFields[$field]['data']), 'loc' => $loc); //if it's not set in the new fields then it was a custom field or an original field so we take the custom fields data and set the location source to custom } else { if (!isset($this->newFields[$field])) { $this->mergedFields[$field] = $data; $this->mergedFields[$field]['loc']['source'] = 'custom'; } else { //otherwise the field is in both new and custom but not in the orignal so we merge the new and custom data together and take the location from the custom $this->mergedFields[$field] = array('data' => $this->mergeField('', $this->newFields[$field]['data'], $this->customFields[$field]['data']), 'loc' => $this->customFields[$field]['loc']); $this->mergedFields[$field]['loc']['source'] = 'custom'; //echo var_export($this->mergedFields[$field], true); } } //then we clear out the field from unset($this->originalFields[$field]); unset($this->customFields[$field]); unset($this->newFields[$field]); } /** * These are fields that were removed by the customer */ foreach ($this->originalFields as $field => $data) { unset($this->originalFields[$field]); unset($this->newFields[$field]); } foreach ($this->newFields as $field => $data) { $data['loc']['source'] = 'new'; $this->mergedFields[$field] = array('data' => $data['data'], 'loc' => $data['loc']); unset($this->newFields[$field]); } }