Default fields mandatory
Posted: 15 Apr 2011, 14:47
Trying to make some default fields mandatory (like product version and comments on status change).
However, when using hte code below, I get an error when the product version is filled in or not (so always actually).
I tried to understand the custom functions (http://docs.mantisbt.org/master/en/admi ... USTOMFUNCS) but have no clue how to adapt this to the fields I want to be mandatory....
However, when using hte code below, I get an error when the product version is filled in or not (so always actually).
Code: Select all
<?php
# --------------------
# Hook to validate field settings before creating an issue
# Verify that the proper fields are set before proceeding to create an issue
# In case of errors, this function should call trigger_error()
# p_new_issue_data is an object (BugData) with the appropriate fields updated
# --------------------
# This code was ripped off and mutated from the following files
# custom_function_api.php,v 1.25 2005/07/23 12:01:48
# bug_view_page.php,v 1.77.6.1.4.1 2007/03/06 07:00:33 and
# bug_api.php,v 1.95.8.1.6.1 2006/04/18 00:53:04 thraxisp
#
# The test for IF there is a product version to select was mutated from bug_view_page.php.
# Should this be a core mantis function found in bug_api.php and is named: is_product_version_visible()?
# bug_create() of bug_api.php for the test for blank value and throwing the correct error message
# --------------------
function custom_function_override_issue_create_validate( $p_new_issue_data ) {
# the purpose of this override is to add to the current validation functionality
# So, call the current validator when creating a new mantis report
# I don't know if this chaining of behavior is MANTIS typical
custom_function_default_issue_create_validate( $p_new_issue_data );
# Decide if product_version is available on the report entry screen being validated for the user
$c_project_id = helper_get_current_project();
$show_product_version_config = config_get( 'show_product_version' );
$show_product_version_counts = count( version_get_all_rows( $c_project_id) );
$is_product_version_visible = ( ON == $show_product_version_config )
|| ( ( AUTO == $show_product_version_config )
&& ( 0 < $show_product_version_counts ) );
if ( $is_product_version_visible ) {
# if the field, product version, is visible to the user,
# then trigger an error if the product version is blank
$c_version = db_prepare_string( $p_bug_data->version );
if ( is_blank( $c_version) ) {
error_parameters( lang_get( 'product_version' ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}
}
}
?>