Skip to content

Commit

Permalink
Show ‘main_menu_custom_options’ in main menu
Browse files Browse the repository at this point in the history
Fixes #21414
  • Loading branch information
vboctor committed Aug 3, 2016
1 parent 0c64599 commit b39075e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
21 changes: 0 additions & 21 deletions core/html_api.php
Expand Up @@ -415,27 +415,6 @@ function html_end() {
}
}

/**
* Prepare an array of additional menu options from a configuration variable
* @param string $p_config Configuration variable name.
* @return array
*/
function prepare_custom_menu_options( $p_config ) {
$t_custom_menu_options = config_get( $p_config );
$t_options = array();

foreach( $t_custom_menu_options as $t_custom_option ) {
$t_access_level = $t_custom_option[1];
if( access_has_project_level( $t_access_level ) ) {
$t_caption = string_html_specialchars( lang_get_defaulted( $t_custom_option[0] ) );
$t_link = string_attribute( $t_custom_option[2] );
$t_options[] = '<a href="' . $t_link . '">' . $t_caption . '</a>';
}
}

return $t_options;
}

/**
* Print the menu bar with a list of projects to which the user has access
* @return void
Expand Down
62 changes: 48 additions & 14 deletions core/layout_api.php
Expand Up @@ -706,17 +706,15 @@ function layout_print_sidebar( $p_active_sidebar_page = null ) {
# Starting sidebar markup
layout_sidebar_begin();

$t_menu_options = array();
# Plugin / Event added options
$t_event_menu_options = event_signal( 'EVENT_MENU_MAIN_FRONT' );
layout_plugin_menu_options_for_sidebar( $t_event_menu_options, $p_active_sidebar_page );

# Main Page
if( config_get( 'news_enabled' ) == ON ) {
layout_sidebar_menu( 'main_page.php', 'main_link', 'fa-bullhorn', $p_active_sidebar_page );
}

# Plugin / Event added options
$t_event_menu_options = event_signal( 'EVENT_MENU_MAIN_FRONT' );
layout_plugin_menu_options_for_sidebar( $t_event_menu_options, $p_active_sidebar_page );

# My View
layout_sidebar_menu( 'my_view_page.php', 'my_view_link', 'fa-dashboard', $p_active_sidebar_page );

Expand Down Expand Up @@ -754,10 +752,6 @@ function layout_print_sidebar( $p_active_sidebar_page = null ) {
layout_sidebar_menu( 'wiki.php?type=project&amp;id=' . $t_current_project, 'wiki', 'fa-book', $p_active_sidebar_page );
}

# Plugin / Event added options
$t_event_menu_options = event_signal( 'EVENT_MENU_MAIN' );
layout_plugin_menu_options_for_sidebar( $t_event_menu_options, $p_active_sidebar_page );

# Manage Users (admins) or Manage Project (managers) or Manage Custom Fields
if( access_has_global_level( config_get( 'manage_site_threshold' ) ) ) {
layout_sidebar_menu( 'manage_overview_page.php', 'manage_link', 'fa-gears', $p_active_sidebar_page );
Expand All @@ -778,15 +772,18 @@ function layout_print_sidebar( $p_active_sidebar_page = null ) {
}
}

# Add custom options
$t_custom_options = prepare_custom_menu_options( 'main_menu_custom_options' );
$t_menu_options = array_merge( $t_menu_options, $t_custom_options );

# Time Tracking / Billing
if( config_get( 'time_tracking_enabled' ) && access_has_global_level( config_get( 'time_tracking_reporting_threshold' ) ) ) {
layout_sidebar_menu( 'billing_page.php', 'time_tracking_billing_link', 'fa-clock-o', $p_active_sidebar_page );
}

# Plugin / Event added options
$t_event_menu_options = event_signal( 'EVENT_MENU_MAIN' );
layout_plugin_menu_options_for_sidebar( $t_event_menu_options, $p_active_sidebar_page );

# Config based custom options
layout_config_menu_options_for_sidebar( $p_active_sidebar_page );

# Ending sidebar markup
layout_sidebar_end();
}
Expand All @@ -813,12 +810,49 @@ function layout_plugin_menu_options_for_sidebar( $p_plugin_event_response, $p_ac
}
}

foreach( $t_menu_options as $t_menu_option ) {
layout_options_for_sidebar( $t_menu_options, $p_active_sidebar_page );
}

/**
* Process main menu options from config.
* @param string $p_active_sidebar_page The active page on the sidebar.
* @return void
*/
function layout_config_menu_options_for_sidebar( $p_active_sidebar_page ) {
$t_menu_options = array();
$t_custom_options = config_get( 'main_menu_custom_options' );

foreach( $t_custom_options as $t_custom_option ) {
$t_menu_option = array();
$t_menu_option['title'] = $t_custom_option[0];
$t_menu_option['access_level'] = $t_custom_option[1];
$t_menu_option['icon'] = 'fa-plug';
$t_menu_option['url'] = $t_custom_option[2];
$t_menu_options[] = $t_menu_option;
}

layout_options_for_sidebar( $t_menu_options, $p_active_sidebar_page );
}

/**
* Process main menu options
* @param array $p_menu_options Array of menu options to output.
* @param string $p_active_sidebar_page The active page on the sidebar.
* @return void
*/
function layout_options_for_sidebar( $p_menu_options, $p_active_sidebar_page ) {
foreach( $p_menu_options as $t_menu_option ) {
$t_icon = isset( $t_menu_option['icon'] ) ? $t_menu_option['icon'] : 'fa-plug';
if( !isset( $t_menu_option['url'] ) || !isset( $t_menu_option['title'] ) ) {
continue;
}

if( isset( $t_menu_option['access_level'] ) ) {
if( !access_has_project_level( $t_menu_option['access_level'] ) ) {
continue;
}
}

layout_sidebar_menu( $t_menu_option['url'], $t_menu_option['title'], $t_icon, $p_active_sidebar_page );
}
}
Expand Down

0 comments on commit b39075e

Please sign in to comment.