Commit a44b2db2 authored by Chris Graham's avatar Chris Graham
Browse files

Fixed MANTIS-4882 (tray_status menu block parameter is ignored)

parent cd159b32
Loading
Loading
Loading
Loading
+0 −0

File changed.

Preview suppressed by a .gitattributes entry or the file's encoding is unsupported.

+1 −1
Original line number Diff line number Diff line
@@ -128,6 +128,6 @@ BLOCK_menu_PARAM_tray_status_TITLE=Tray status
BLOCK_menu_PARAM_silent_failure_TITLE=Silent failure
BLOCK_menu_PARAM_javascript_highlighting_TITLE=JavaScript highlighting
BLOCK_menu_PARAM_param=The name of the menu. Choose an existing menu name, or enter a new name. If you enter a new name then when you later view the block (by viewing the page) you will see the block invites you to add the missing menu.
BLOCK_menu_PARAM_tray_status=The default tray status for the menu (must be either 'tray_open', 'tray_closed', or '' [blank]). Default: ''.
BLOCK_menu_PARAM_tray_status=The default tray status for the menu if generated from the Sitemap (must be either 'tray_open' or 'tray_closed'). Note that with default templates is only meaningful for the 'tree' menu type, and only when there is no URL on the branch (as click-to-expand on 'tree' menus is only a feature when the link on the branch isn't serving that branches own URL). Default: ''.
BLOCK_menu_PARAM_silent_failure=Whether no error message is to be output, if the menu does not exist. Default: '0'.
BLOCK_menu_PARAM_javascript_highlighting=Whether JavaScript will be used to highlight active screen(s) in the menu. This improves performance because the block can be singularly cached rather than separately by page. Default: '1'.
+3 −3
Original line number Diff line number Diff line
@@ -95,12 +95,12 @@ class Block_menu

        $silent_failure = ((isset($map['silent_failure']) ? $map['silent_failure'] : '0') == '1');

        $tray_status = isset($map['tray_status']) ? $map['tray_status'] : '';
        $tray_status = empty($map['tray_status']) ? 'tray_closed' : $map['tray_status'];

        $javascript_highlighting = ((isset($map['javascript_highlighting']) ? $map['javascript_highlighting'] : '1') == '1');

        require_code('menus');
        list($content, $root, $flattened) = build_menu($type, $menu, false, !$javascript_highlighting);
        list($content, $root, $flattened) = build_menu($type, $menu, false, !$javascript_highlighting, $tray_status);
        if ($flattened) {
            $LANGS_REQUESTED = $bak; // We've flattened with apply_quick_caching, we don't need to load up all those language files next time
        }
@@ -154,7 +154,7 @@ function block_menu__cache_on($map)
        isset($map['type']) ? $map['type'] : 'embossed',
        isset($map['title']) ? $map['title'] : '',
        ((isset($map['silent_failure']) ? $map['silent_failure'] : '0') == '1'),
        isset($map['tray_status']) ? $map['tray_status'] : '',
        empty($map['tray_status']) ? 'tray_closed' : $map['tray_status'],
        tacit_https(),
    );

+33 −5
Original line number Diff line number Diff line
@@ -50,14 +50,16 @@ function is_sitemap_menu($menu)
 * @param  SHORT_TEXT $menu The menu identifier to use (may be the name of a editable menu, or syntax to load from the Sitemap)
 * @param  boolean $silent_failure Whether to silently return blank if the menu does not exist
 * @param  boolean $apply_highlighting Whether to apply current-screen highlighting
 * @param  string $tray_status The default expansion status of the node
 * @set tray_open tray_closed
 * @return array A tuple: The generated Tempcode of the menu, the menu nodes, whether we flattened
 */
function build_menu($type, $menu, $silent_failure = false, $apply_highlighting = true)
function build_menu($type, $menu, $silent_failure = false, $apply_highlighting = true, $tray_status = 'tray_closed')
{
    $is_sitemap_menu = is_sitemap_menu($menu);

    if ($is_sitemap_menu) {
        $root = _build_sitemap_menu($menu);
        $root = _build_sitemap_menu($menu, $tray_status);

        if ($root === null) {
            return array(new Tempcode(), array(), false);
@@ -186,10 +188,12 @@ function _build_stored_menu($menu)
 * Take a menu identifier, and return a Sitemap-based menu created from it.
 *
 * @param  SHORT_TEXT $menu The menu identifier to use (syntax to load from the Sitemap)
 * @param  string $tray_status The default expansion status of the node
 * @set tray_open tray_closed
 * @return array The Sitemap node structure (called a 'branch structure' for menus)
 * @ignore
 */
function _build_sitemap_menu($menu)
function _build_sitemap_menu($menu, $tray_status = 'tray_closed')
{
    static $cache = array();
    if (isset($cache[$menu])) {
@@ -331,6 +335,10 @@ function _build_sitemap_menu($menu)
                $root['children'][] = $node;
                break;
        }

        if ($tray_status == 'tray_open') {
            _recursively_set_expanded($root);
        }
    }

    $cache[$menu] = $root;
@@ -338,6 +346,26 @@ function _build_sitemap_menu($menu)
    return $root;
}

/**
 * Set node expansion on the whole hierarchy of Sitemap nodes.
 *
 * @param array $node The node
 *
 * @ignore
 */
function _recursively_set_expanded(&$node)
{
    if (!isset($node['modifiers']['expanded'])) {
        $node['modifiers']['expanded'] = 1;
    }

    if (isset($node['children'])) {
        foreach ($node['children'] as &$child) {
            _recursively_set_expanded($child);
        }
    }
}

/**
 * Get root branch (an empty shell).
 *
@@ -757,8 +785,8 @@ function _render_menu_branch($branch, $codename, $source_member, $level, $type,
    $tooltip = isset($branch['extra_meta']['description']) ? $branch['extra_meta']['description'] : new Tempcode();

    // How to display
    if ((!isset($branch['modifiers']['expanded'])) && (!$expand_this) && (!$current_page) && ($page_link == '')) {
        $display = has_js() ? 'none' : 'block'; // We remap to 'none' using JS. If no JS, it remains visible. Once we have learn't we have JS, we don't need to do it again
    if ((!isset($branch['modifiers']['expanded'])) && (!$expand_this) && (!$current_page)) {
        $display = has_js() ? 'none' : 'block'; // We remap to 'none' if we have JS. If no JS is detected/assumed-by-configuration, it remains visible.
    } else {
        $display = 'block';
    }
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
		{+END}
	{+END}
	{+START,IF,{$GET,HAS_CHILDREN}}
		<ul aria-haspopup="true" id="{MENU|;*}_{$GET*,RAND}" style="display: {DISPLAY*}">
		<ul aria-haspopup="true" id="{MENU|;*}_{$GET*,RAND}"{+START,IF_EMPTY,{URL}} style="display: {DISPLAY*}"{+END}>
			{CHILDREN}
		</ul>
	{+END}