Skip to content

Commit

Permalink
Fix ability to purge value of a custom field
Browse files Browse the repository at this point in the history
Fixes #20002
  • Loading branch information
vboctor committed Aug 28, 2015
1 parent 540a79b commit 047f5aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
12 changes: 6 additions & 6 deletions bug_update.php
Expand Up @@ -276,6 +276,12 @@
foreach ( $t_related_custom_field_ids as $t_cf_id ) {
$t_cf_def = custom_field_get_definition( $t_cf_id );

# if this is not a full update action and custom field is not on the form, then don't
# continue with code that checks access level and validates the field.
if ( $f_update_type != BUG_UPDATE_TYPE_NORMAL && !custom_field_is_present( $t_cf_id ) ) {
continue;
}

if( !gpc_isset_custom_field( $t_cf_id, $t_cf_def['type'] ) ) {
if( $t_cf_def[$t_cf_require_check] &&
$f_update_type == BUG_UPDATE_TYPE_NORMAL &&
Expand All @@ -284,12 +290,6 @@
# no value was given by the user.
error_parameters( lang_get_defaulted( custom_field_get_field( $t_cf_id, 'name' ) ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
} else {
# The custom field isn't compulsory and the user did
# not supply a value. Therefore we can just ignore this
# custom field completely (ie. don't attempt to update
# the field).
continue;
}
}

Expand Down
19 changes: 19 additions & 0 deletions core/custom_field_api.php
Expand Up @@ -1269,11 +1269,30 @@ function print_custom_field_input( array $p_field_def, $p_bug_id = null ) {
global $g_custom_field_type_definition;
if( isset( $g_custom_field_type_definition[$p_field_def['type']]['#function_print_input'] ) ) {
call_user_func( $g_custom_field_type_definition[$p_field_def['type']]['#function_print_input'], $p_field_def, $t_custom_field_value );
print_hidden_input( custom_field_presence_field_name( $p_field_def['id'] ), '1' );
} else {
trigger_error( ERROR_CUSTOM_FIELD_INVALID_DEFINITION, ERROR );
}
}

/**
* Constructs the name of a field used as a flag to indicate that a custom field is present on the form
* @param integer $p_custom_field_id The custom field id to create the field name for.
* @return string The field name.
*/
function custom_field_presence_field_name( $p_custom_field_id ) {
return 'custom_field_' . (int)$p_custom_field_id . '_presence';
}

/**
* Checks the presence of a custom field on the form.
* @param integer $p_custom_field_id The custom field id to check.
* @return bool true when field is on form, false otherwise.
*/
function custom_field_is_present( $p_custom_field_id ) {
return gpc_isset( custom_field_presence_field_name( $p_custom_field_id ) );
}

/**
* Prepare a string containing a custom field value for display
* @param array $p_def Contains the definition of the custom field.
Expand Down

0 comments on commit 047f5aa

Please sign in to comment.