Skip to content

Commit

Permalink
Allow custom fallback status color
Browse files Browse the repository at this point in the history
When no color is defined in $g_status_color for a given status,
get_status_color() falls back to a hardcoded pure white (#ffffff).

This lets the caller specify which color to use in this case.

Issue #25523
  • Loading branch information
dregad committed Mar 2, 2019
1 parent 0012eda commit 45dca87
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/helper_api.php
Expand Up @@ -110,29 +110,29 @@ function helper_array_transpose( array $p_array ) {
* @param string $p_status_label Status label.
* @param integer|null $p_user User id, defaults to null (all users).
* @param integer|null $p_project Project id, defaults to null (all projects).
* @param string $p_default_color Fallback color in case status is not found (defaults to white).
* @return string
*/
function get_status_color_by_label( $p_status_label, $p_user = null, $p_project = null ) {
function get_status_color_by_label( $p_status_label, $p_user = null, $p_project = null, $p_default_color = '#ffffff' ) {
$t_status_colors = config_get( 'status_colors', null, $p_user, $p_project );
$t_color = '#ffffff';

if( isset( $t_status_colors[$p_status_label] ) ) {
$t_color = $t_status_colors[$p_status_label];
return $t_status_colors[$p_status_label];
}

return $t_color;
return $p_default_color;
}

/**
* get the color string for the given status, user and project
* @param integer $p_status Status value.
* @param integer|null $p_user User id, defaults to null (all users).
* @param integer|null $p_project Project id, defaults to null (all projects).
* @param integer $p_status Status value.
* @param integer|null $p_user User id, defaults to null (all users).
* @param integer|null $p_project Project id, defaults to null (all projects).
* @param string $p_default_color Fallback color in case status is not found (defaults to white).
* @return string
*/
function get_status_color( $p_status, $p_user = null, $p_project = null ) {
function get_status_color( $p_status, $p_user = null, $p_project = null, $p_default_color = '#ffffff' ) {
$t_status_label = MantisEnum::getLabel( config_get( 'status_enum_string', null, $p_user, $p_project ), $p_status );
return get_status_color_by_label( $t_status_label, $p_user, $p_project );
return get_status_color_by_label( $t_status_label, $p_user, $p_project, $p_default_color );
}

/**
Expand Down

0 comments on commit 45dca87

Please sign in to comment.