Skip to content

Commit

Permalink
Handling single category case
Browse files Browse the repository at this point in the history
If there is a single category and it is required to set the category
field, then auto-select such category.

Fixes #19264
  • Loading branch information
vboctor committed Feb 4, 2015
1 parent 3a29ba7 commit 7629ad8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/print_api.php
Expand Up @@ -698,22 +698,27 @@ function print_category_option_list( $p_category_id = 0, $p_project_id = null )
} else {
$t_project_id = $p_project_id;
}

$t_cat_arr = category_get_all_rows( $t_project_id, null, true );

if( config_get( 'allow_no_category' ) ) {
echo '<option value="0"';
check_selected( $p_category_id, 0 );
echo '>';
echo category_full_name( 0, false ), '</option>';
} else {
if( 0 == $p_category_id ) {
echo '<option value="0"';
echo check_selected( $p_category_id, 0 );
echo '>';
echo string_attribute( lang_get( 'select_option' ) ) . '</option>';
if( count( $t_cat_arr ) == 1 ) {
$p_category_id = (int) $t_cat_arr[0]['id'];
} else {
echo '<option value="0"';
echo check_selected( $p_category_id, 0 );
echo '>';
echo string_attribute( lang_get( 'select_option' ) ) . '</option>';
}
}
}

$t_cat_arr = category_get_all_rows( $t_project_id, null, true );

foreach( $t_cat_arr as $t_category_row ) {
$t_category_id = (int)$t_category_row['id'];
echo '<option value="' . $t_category_id . '"';
Expand Down

0 comments on commit 7629ad8

Please sign in to comment.