Esempio n. 1
0
 /**
  * Process the field vardefs as setup by the extending classes
  */
 protected function processFields()
 {
     // get the get_widget helper and the StandardField Helper
     SugarAutoLoader::load('modules/DynamicFields/FieldCases.php');
     SugarAutoLoader::load('modules/ModuleBuilder/parsers/StandardField.php');
     foreach ($this->field_vardef_setup as $field => $new_defs) {
         // get the field defs
         $field_defs = $this->bean->getFieldDefinition($field);
         // load the field type up
         $f = get_widget($field_defs['type']);
         $diff = array();
         foreach ($new_defs as $k => $v) {
             if (!isset($field_defs[$k])) {
                 switch ($k) {
                     case 'massupdate':
                     case 'studio':
                     case 'reportable':
                     case 'workflow':
                         if (!$v) {
                             $diff[$k] = $v;
                         }
                         break;
                     default:
                         if ($v) {
                             $diff[$k] = $v;
                         }
                 }
             } elseif ($field_defs[$k] != $v) {
                 $diff[$k] = $v;
             }
         }
         if (empty($diff)) {
             continue;
         }
         // populate the row from the vardefs that were loaded and the new_defs
         $f->populateFromRow(array_merge($field_defs, $diff));
         // now lets save, since these are OOB field, we use StandardField
         $df = new StandardField($this->bean->module_name);
         $df->setup($this->bean);
         $f->module = $this->bean;
         // StandardField considers only the attributes which can be edited in Studio,
         // while the "studio" attribute is not one of them. we need to change the vardef map temporarily here,
         // because changing it permanently will make the "studio" attribute always overridden with empty value,
         // after the field has been saved in Studio
         if (!isset($f->vardef_map['studio'])) {
             $f->vardef_map['studio'] = 'studio';
         }
         $f->save($df);
     }
 }
Esempio n. 2
0
 /**
  * Process the ListView to set the fields correctly
  *
  * @param array $fieldMap
  * @param $current_fields
  * @param ListLayoutMetaDataParser $listParser
  */
 private function processList(array $fieldMap, $current_fields, ListLayoutMetaDataParser $listParser)
 {
     if (!$listParser instanceof SidecarListLayoutMetaDataParser) {
         return false;
     }
     $handleSave = false;
     $saveFields = array();
     // process the fields
     foreach ($current_fields as $panel_id => $panel) {
         if (is_array($panel['fields'])) {
             foreach ($panel['fields'] as $field) {
                 $name = $field['name'];
                 $addField = true;
                 $additionalDefs = $field;
                 if (isset($fieldMap[$name])) {
                     if ($fieldMap[$name] === true) {
                         // nothing to do, field is present
                     } elseif ($fieldMap[$name] !== false) {
                         // we have the field, so get it's defs
                         $defs = $this->bean->getFieldDefinition($fieldMap[$name]);
                         if ($defs) {
                             // set the name variable to the new field name.
                             $name = $fieldMap[$name];
                             // reset the additionDefs since we have a new field
                             $additionalDefs = array();
                         } else {
                             // we didn't find any defs for the new field, so error on caution and remove the old one
                             $addField = false;
                         }
                         $handleSave = true;
                     } else {
                         // instead of a name being passed in, false was, so we should remove that field.
                         $addField = false;
                         $handleSave = true;
                     }
                     unset($fieldMap[$name]);
                 }
                 if ($addField) {
                     $saveFields[] = array($name, $additionalDefs);
                 }
             }
         }
     }
     // make sure that the field map is empty, if it's not process any remaining fields
     if (!empty($fieldMap)) {
         foreach ($fieldMap as $field => $trigger) {
             if ($trigger === true) {
                 $defs = $this->bean->getFieldDefinition($field);
                 if ($defs) {
                     $saveFields[] = array($field, array());
                     $handleSave = true;
                 }
             }
         }
     }
     if ($handleSave) {
         // make sure the list is reset
         $listParser->resetPanelFields();
         foreach ($saveFields as $params) {
             $listParser->addField($params[0], $params[1]);
         }
         $listParser->handleSave(false);
     }
 }