Add Custom Field Type to Sugar Logic

I have a custom field type for an auto-increment field. Using this guide we have almost all the functionality we would like:

http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.9/User_Interface/Fields/Creating_Custo… 

One exception is the field is not available to use in Sugar Logic. I have tracked down the function that populates this data to the cleanFields method in modules/ExpressionEngine/formulaHelper.php. Manually modifying this function adds the field to the select field list while building a Sugar Logic formula but I cannot figure out how to achieve this without modifying the core file.

Copying and extending to custom/modules/ExpressionEngine/formulaHelper.php didn't do the trick. I also copied and extended what I think is the view for this at custom/modules/ExpressionEngine/views/view.editformula.php but this didn't work either.

Any ideas on how to implement this for On-Demand environments?

Note that the class FormulaHelper at modules/ExpressionEngine/formulaHelper.php is auto-loaded in cache/class_map.php

Thank you

  • I was able to figure this out with the following:

    Add file custom/modules/ExpressionEngine/views/view.editformula.php

    <?php
    /*
    * Your installation or use of this SugarCRM file is subject to the applicable
    * terms available at
    * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.
    * If you do not agree to all of the applicable terms or do not have the
    * authority to bind the entity as an authorized representative, then do not
    * install or use this SugarCRM file.
    *
    * Copyright (C) SugarCRM Inc. All rights reserved.
    */

    require_once('modules/ExpressionEngine/views/view.editformula.php');
    require_once('custom/modules/ExpressionEngine/formulaHelper.php');
    class CustomViewEditFormula extends ViewEditFormula
    {
        public function __construct()
        {

            parent::__construct();

       }

       function display(){
          global $app_strings, $current_user, $mod_strings, $theme, $beanList, $beanFiles;
          $smarty = new Sugar_Smarty();
          $json = new JSON();
          //Load the field list from the target module
            if(!empty($_REQUEST['targetModule']) && $_REQUEST['targetModule'] != 'undefined')
          {
             $module = $_REQUEST['targetModule'];
             if (isset($_REQUEST['package']) && $_REQUEST['package'] != 'studio' && $_REQUEST['package'] != '') {
                //Get the MB Parsers
                $pak = new MBPackage($_REQUEST['package']);
                $defs = $pak->modules[$module]->getVardefs();
                    $fields = CustomFormulaHelper::cleanFields(array_merge($pak->modules[$module]->getLinkFields(), $defs['fields']));
             } else {
                 $seed = BeanFactory::newBean($module);
                  $fields = CustomFormulaHelper::cleanFields($seed->field_defs);
             }
               $smarty->assign('Field_Array', $json->encode($fields));
          }
          else
          {
             $fields = array(array('income', 'number'), array('employed', 'boolean'), array('first_name', 'string'), array('last_name', 'string'));
             $smarty->assign('Field_Array', $json->encode($fields));
          }

            $request_target_field = $this->request->getValidInputRequest('targetField');
            $smarty->assign("target", $request_target_field);

            $request_return_type = $this->request->getValidInputRequest('returnType');
            $smarty->assign("returnType", $request_return_type);

          //Check if we need to load Ext ourselves
          if (!isset($_REQUEST['loadExt']) || ($_REQUEST['loadExt'] && $_REQUEST['loadExt'] != "false"))
          {
             $smarty->assign('loadExt', true);
          } else
          {
             $smarty->assign('loadExt', false);
          }
            $request_formula = $this->request->getValidInputRequest('formula');
            $smarty->assign('formula', $json->decode($request_formula));

          $smarty->assign('app_strings', $app_strings);
          $smarty->assign('mod', $mod_strings);
          $smarty->display('modules/ExpressionEngine/tpls/formulaBuilder.tpl');
       }
    }

    Then add custom/modules/ExpressionEngine/formulaHelper.php

    <?php
    /*
    * Your installation or use of this SugarCRM file is subject to the applicable
    * terms available at
    * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.
    * If you do not agree to all of the applicable terms or do not have the
    * authority to bind the entity as an authorized representative, then do not
    * install or use this SugarCRM file.
    *
    * Copyright (C) SugarCRM Inc. All rights reserved.
    */

    require_once('modules/ExpressionEngine/formulaHelper.php');
    class CustomFormulaHelper extends FormulaHelper

    {

        /**
         * Takes an array of field defs and returns a formated list of fields that are valid for use in expressions.
         *
         * @param array $fieldDef
         * @return array
         */
        public static function cleanFields($fieldDef, $includeLinks = true, $forRelatedField = false, $returnKeys = false)
        {
            $fieldArray = array();
            foreach ($fieldDef as $fieldName => $def) {
                if (!is_array($def) || $fieldName == 'deleted' || $fieldName == 'email1' || empty($def['type']))
                    continue;
                //Check the studio property of the field def.
                if (isset($def['studio']) && (self::isFalse($def['studio']) || (is_array($def['studio']) && (
                                (isset($def['studio']['formula']) && self::isFalse($def['studio']['formula'])) ||
                                ($forRelatedField && isset($def['studio']['related']) && self::isFalse($def['studio']['related']))
                            ))))
                {
                    continue;
                }
                switch ($def['type']) {
                    case "int":
                    case "float":
                    case "decimal":
                    case "discount":
                    case "currency":
                   // Custom field type here
                    case "Autoincrementfield":
                        $fieldArray[$fieldName] = array($fieldName, 'number');
                        break;
                    case "bool":
                        $fieldArray[$fieldName] = array($fieldName, 'boolean');
                        break;
                    case "varchar":
                    case "name":
                    case "phone":
                    case "text":
                    case "url":
                    case "encrypt":
                    case "enum":
                    case "radioenum":
                        $fieldArray[$fieldName] = array($fieldName, 'string');
                        break;
                    case 'fullname':
                        if ($forRelatedField) {
                            $fieldArray[$fieldName] = array($fieldName, 'string');
                        }
                        break;
                    case "date":
                    case "datetime":
                    case "datetimecombo":
                        $fieldArray[$fieldName] = array($fieldName, 'date');
                        break;
                    case "link":
                        if ($includeLinks)
                            $fieldArray[$fieldName] = array($fieldName, 'relate');
                        break;
                    default:
                        //Do Nothing
                        break;
                }
            }

            if ($returnKeys)
                return $fieldArray;

            return array_values($fieldArray);
        }


    }

    Thought I had tried this previously but must have had something messed up.

    Would have preferred updating the Autoloader but didn't seem to catch.