Donāt you just love it?
Iāve been working on this for two days and just after posting this, I found a solution.
Details are at
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.0/Architecture/Languages/Managing_Lists/index.html
where you access the class DropDownHelper from {SuiteCRM_Directory}/modules/Studio/DropDowns/DropDownHelper.php
but below is the summary.
Create a custom module (AYU_CharitableProjects) whose only purpose is to set the Dropdown list values. This way, you know the only way the dropown list values change is when someone wants them to change. Also, by creating a sepoarate custom module, you can save the list for different events and return to that if/as needed.
The only field I added to the custom module was a TextArea field: fund_project_list_c
Use SuiteCRMās Admin-DropDown Editor to create a Dropdown called funds_project_dom_list and give it one entry (for now)
GeneralUse => General Use
into {SuiteCRM_Directory}/custom/Extension/modules/AYU_CharitableProjects/Ext/LogicHooks/setFundsProjectList.php
<?php
$hook_version = 1;
$hook_array = Array();
// position, file, function
//
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(
80,
'Update Dropdown list of Charity Projects',
'custom/modules/AYU_CharitableProjects/listCharityProjects.php',
'listCharityProjects',
'userInputList',
);
into {SuiteCRM_Directory}/custom/modules/AYU_ChartiableProjects/listCharityProjects.phpā put
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class listCharityProjects {
function userInputList( $bean, $events , $arguments ) {
// Set the dropdown list for the Charitable Projects
// so each Event can use a Project list specific to that Event
// The dropdown list is just used as a filter for what is allowed as input
// Once input is saved (into the MySQL database as text)
// The dropdown list can be edited for future uses
if ( !empty($bean->fund_project_list_c) && ( $bean->fund_project_list_c != NULL )) {
require_once 'modules/Studio/DropDowns/DropDownHelper.php';
$dropdownEditor = new DropDownHelper();
// Initialize the arrays to be used to update the dropdown list
$tempListArray = array();
// Use as the Name, the name given to the list when it was created (Studio?)
$tempListArray['dropdown_name'] = 'funds_project_dom_list';
// Set the first choice of the list to "General Use"
// See below for an explanation of the syntax
$tempListArray['slot_'. 0] = 0;
$tempListArray['key_'. 0] = 'GeneralUse';
$tempListArray['value_'. 0] = 'General Use';
$tempListArray['use_push'] = '';
// We start the array list at 1 since we have the first (0) entry set above
$itemCount = 1;
$sourceTextArray = explode( PHP_EOL , $bean->fund_project_list_c );
foreach( $sourceTextArray as $key => $listEntry ) {
// Convert the source text into an array
$cleanString = trim( filter_var( $listEntry , FILTER_SANITIZE_STRING , FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK ) );
$indexString = preg_replace( "/[^A-Za-z0-9-]/" , '' , $cleanString );
// Use the array contents to populate the inputs needed
// by DropdownHelper
$tempListArray['slot_'. $itemCount] = $itemCount;
$tempListArray['key_'. $itemCount] = $indexString;
$tempListArray['value_'. $itemCount] = $cleanString;
// Set 'use_push' to true to update/add values while keeping old values
// Set "use_push' to empty ('') to delete old values and replace with these
$tempListArray['use_push'] = '';
$itemCount++;
}
// Save the new dropdown list
$dropdownEditor->saveDropDown($tempListArray);
}
}
}
Repair and Rebuild
Create a Dropdown field in whaever module you want and have it use, as its list: funds_project_dom_list
Create an (or open an existing) entry in CharitableProjects with some list items entered into the TextArea and Save the entry.
This updates the dom list with what you have in the TextArea and puts a filtered version of the TextArea entry as the ItemIndex.