Sugar handles dropdown menus differently than it handles module data. Module data is stored in the database. Dropdown menu choices are stored in arrays inside of Sugar. If you think about it, this makes a lot of sense, otherwise you'd have a different look-up table for every dropdown field in each Sugar view. Putting look up tables in the database, in Sugar's case, would make an already large database schema overwhelmed with tables, and slow down loading the views.
A dropdown field is a data field in a view that has a little arrow to the right of the input field box. When you click on the arrow, a vertical menu of possible choices appears, all the States in the U.S. for example. You click on your menu choice, like PA, and it appears as your choice when saving that record. The advantage of the dropdown menu is it limits the user's choices for that field to only what's in the menu. This in turn makes coding with that field much easier, because you don't have to deal with free form text choices, and validation. It also makes reports easier, because everything is put into groups defined by the dropdown menu choices.
Sugar attempts to make dropdown menus easy by having most of the functionality accessed via Studio. Let's take a look at that first, and then we'll dig into the code a little bit.
To create a new dropdown field in Sugar, you go to Studio, pick out the module where you want the new field to appear, inside the module, click on "Fields," and then "Add Field". You then pick out the "Data Type" for your new field by clicking on the "Data Type" dropdown button, and picking "DropDown." Sugar then shows specific fields just used for the Dropdown data type. You can create an entirely new dropdown menu by clicking "Add," or "Edit" an existing list by picking that list in the "Drop Down List."
It's easy to change the choices in an existing dropdown menu by clicking "Edit" and adding new choices, or relabeling your existing choices. You can set a "Default Value" that the field will be set to initially. In the application, When you choose PA as your state in the dropdown, and save the record, that particular record will have PA as the state in the database.
The "DropDown List" is a list of the dropdown lists in your Sugar application.
If you want to edit the choices in a particular dropdown menu without going through the Studio module, Sugar also has a "Dropdown Editor" in the Admin panel where you can pick from a list of "almost" all the lists in Sugar to edit. You noticed I said "almost," bear with me a bit more until I talk about code and files.
Linking dropdown lists is a new functionality with Sugar version 6. A linked dropdown list means if a user selects a choice in a dropdown, another dropdown field will appear with limited choices. For example, if you selected a State, a City field would appear in the application that would only have a list of the cities in that State. If you selected another state, only the cities in the new
state would appear in the city field, and so on. Sugar has made this powerful functionality fairly easy to create and edit in Studio.
To link dropdown lists, first, select "Parent Dropdown" in the "Dependent" field, and in the Parent Dropdown field, select the menu you want as your parent, in our example, States. To link the menu your currently editing, to the choices in a parent dropdown list, you click on "Edit Visibility" and a graphic interface comes up similar to the layout screens.
This can get a little confusing. Available Options on the left are the dropdown menu choices in the child dropdown menu. In our previous example, this menu would list all the cities in the U.S. On the right you'll see boxes with labels on the top. The top labels on the boxes to the right are the dropdown menu choices from the parent dropdown. In our example, there would be 52 boxes corresponding to the states. To set up the cascading menus, you drag a city to the corresponding state box. You can order the menu choices by dragging the cities within the state box. Once finished, if you click on a state in your edit view, the city field will appear with just those state's cities as dropdown choices. Pretty neat. You can continue linking your lists to as many layers as you want, you're not limited to one parent and child.
Now to the code, all the dropdown arrays are stored in Sugar in "custom/include/language/en_us.lang.php", or the language of your choice. As you can imagine this file can get quite long. Every dropdown list in Sugar, with a few exceptions, is in this file.
Let's take a look at how one drop list is stored in the array.
The dropdown list name is in the first $Globals line, in this case, "interaction_method_list." Then follows your array of choices. These particular menu choices are: Email, Event, Fax, Letter, Phone, and Other. Knowing this you can quickly correct any problems that were not easily overcome in Sugar. Remember to rebuild the application after any changes.
Linked lists, that depend on parent menu choices, are handled slightly differently. They are stored in "custom/Extension/modules/[your module]/Ext/Vardefs/" Here the child menus appear in separate files as sub arrays of the parent array. These files are used to auto-generate other files to create what you see in the application. There are other choices in these files that describe the field. However, I recommend you use Studio to do your edits in linked lists. The best way to make changes to this file is in Studio itself through its visual interface.
There is one other problem that you should be aware of that stumped me for awhile that may occur with dropdown lists. Here's what the problem looks like:
How do I edit my dropdown list in Studio. If you look at the earlier pictures you'll see an "Edit" and "Add" button under the "Drop Down List." In this picture, there is no edit or add button, just the dropdown list name. What happened? How do I edit my menu choices?
If you go to the Dropdown Editor in Studio, there's another surprise for you, that dropdown menu is not listed with all the other dropdown lists. What happened to it? I see the dropdown in Studio and I have choices, but how do I edit the choices?
Well, after much looking, I found Sugar has a "special," mostly undocumented, feature to hide dropdown menus from users and make them uneditable. They hide this from developers by locating the list in "modules/ModuleBuilder/Module/DropDownBrowser.php". Now, who would have thought to look in that folder and file? The top of the file looks like this:
If you remove the eamp_list from the array, you'll find it will magically appear in your dropdown menu list, and in Studio with an "Add" and "Edit" button, and be editable. Happy Coding.