prepareIndentedMenuTree (function)

Last updated: Fri, May 26, 2023 9:52 am
Return to Knowledgebase

Purpose

The prepareIndentedMenuTree function in UserSpice is a custom function used to retrieve a menu tree and indent it based on a specified property.

Location

users/helpers/menus.php

Parameters

# Parameter Data Type Required Description
1 $menuResults array Yes The menu data used to build the tree. This data should be in the form of an array with each element representing a menu item.

Returns

Data Type Description of Returned Data
array The function returns an array representing the indented menu tree.

Further Documentation:

$menuResults = [
[
'id' => 1,
'parent' => 0,
'display_order' => 1,
'menu_title' => 'Home',
// Other menu item properties
],
[
'id' => 2,
'parent' => 1,
'display_order' => 2,
'menu_title' => 'About',
// Other menu item properties
],
// Other menu items
];

// Get the indented menu tree
$menuIndentedTree = prepareIndentedMenuTree($menuResults);

print_r($menuIndentedTree);


In the example above, the prepareIndentedMenuTree function is called with the $menuResults array as an argument. This array contains the menu data used to build the tree. Each element of the array represents a menu item and contains properties such as id, parent, display_order, and menu_title.

The function uses the treeManager class to retrieve the menu tree by calling