mantisbt:dynamic_enum_custom_fields
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
mantisbt:dynamic_enum_custom_fields [2008/01/27 22:31] – created vboctor | mantisbt:dynamic_enum_custom_fields [2009/04/21 03:36] (current) – ckchan | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Enumeration Custom Fields with Dynamic Possible Values ====== | ||
+ | ===== Introduction ===== | ||
+ | |||
+ | Starting with Mantis 1.1.0rc1, it is possible to define enumeration custom fields that have a dynamic set of possible values. The possible values are constructed via a custom function. The implementation of the custom function can depend on the context (current project, current user, current user's access level). | ||
+ | |||
+ | Usually when an enumeration custom field is defined, the possible values are defined as " | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== How to do it? ===== | ||
+ | |||
+ | If the user selects " | ||
+ | |||
+ | Following is a sample custom function that is used to populate a field with the categories belonging to the currently selected project: | ||
+ | |||
+ | <code php> | ||
+ | # -------------------- | ||
+ | # custom_function_api.php | ||
+ | # Construct an enumeration for all categories for the current project. | ||
+ | # The enumeration will be empty if current project is ALL PROJECTS. | ||
+ | # Enumerations format is: " | ||
+ | # To use this in a custom field name " | ||
+ | function custom_function_override_enum_categories() { | ||
+ | $t_categories = category_get_all_rows( helper_get_current_project() ); | ||
+ | |||
+ | $t_enum = array(); | ||
+ | foreach( $t_categories as $t_category ) { | ||
+ | $t_enum[] = $t_category[' | ||
+ | } | ||
+ | |||
+ | $t_possible_values = implode( ' | ||
+ | |||
+ | return $t_possible_values; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Notice the following: | ||
+ | |||
+ | * The custom function doesn' | ||
+ | * The custom function returns the possible values in the format (A|B|C). | ||
+ | * The custom function uses the current project. | ||
+ | * The custom function builds on top of the already existing APIs. | ||
+ | |||
+ | To define your own function for custom field (name = " | ||
+ | |||
+ | <code php> | ||
+ | # -------------------- | ||
+ | # To use this in a custom field name = " | ||
+ | function custom_function_override_enum_mine() { | ||
+ | $t_enum = array(); | ||
+ | |||
+ | : | ||
+ | |||
+ | $t_possible_values = implode( ' | ||
+ | |||
+ | return $t_possible_values; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Notice " | ||
+ | |||
+ | As usual, when you upgrade Mantis to future releases, your custom functions will not be overwritten. The difference between the " |
mantisbt/dynamic_enum_custom_fields.txt · Last modified: 2009/04/21 03:36 by ckchan