Product SiteDocumentation Site

7.2.7.2. Defining Custom Dynamic Possible Values

If the user selects =versions, the actual custom function that is executed is custom_function_*_enum_versions(). The reason why the "enum_" is not included is to have a fixed prefix for all custom functions used for this purpose and protect against users using custom functions that were not intended for this purpose.
For example, you would not want the user to use custom_function_*_issue_delete_notify() which may be overridden by the web master to delete associated data in other databases.
Following is a sample custom function that is used to populate a field with the categories belonging to the currently selected project:
/**
 * Construct an enumeration for all categories for the current project.
 *
 * The enumeration will be empty if current project is ALL PROJECTS.
 * Enumerations format is: "abc|lmn|xyz"
 * To use this in a custom field type "=categories" in the possible values field.
 */
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['category'];
	}

	$t_possible_values = implode( '|', $t_enum );

	return $t_possible_values;
}

Note

  • The custom function doesn't take any parameters.
  • 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 mine, you will have to define it with the following signature:
/**
 * Use this in a custom field type "=mine" in the possible values field.
 */
function custom_function_override_enum_mine() {
	# Populate $t_enum values as appropriate here
	$t_enum = array();

	$t_possible_values = implode( '|', $t_enum );

	return $t_possible_values;
}

Note

Notice the override in the function name. This is because this method is defined by the MantisBT administrator and not part of the MantisBT source. It is OK to override a method that doesn't exist.
As usual, when MantisBT is upgraded to future releases, the custom functions will not be overwritten. The difference between the "default" implementation and the "override" implementation is explained in more details in Section 7.6, “Custom Functions”.