Documentation

Menu
in package
implements ArrayAccess Uses BackwardCompatibility, ArrayAccessHelper

Represents a menu, such as the admin menu or profile menu.

The $data parameter for the constructor is array of sections, which contain areas, which can contain subsections. The properties for each are as follows:

For Sections:

string title:         Section title.

bool   enabled:       Should this section be accessible?

array  areas:         Array of areas within this section. (See below.)

array  permission:    Permission required to access the whole section.

For Areas:

string label:         Optional text string for link. If this is not set,
                      Lang::$txt[$area_id] will be used.

string file:          Name of source file required for this area.

string function:      Function to call when area is selected.

string custom_url:    URL to use for this menu item.

bool   enabled:       Should this area be accessible?

bool   hidden:        Should this area be visible? (Used when an area is
                      accessible but should not be shown.)

string select:        If set this item will not be displayed. Instead the
                      item indexed here will be.

array  subsections:   Array of subsections from this area. (See below.)

array  permission:    Array of permissions to determine who can access
                      this area.

For Subsections:

string label:         Text label for this subsection.

array  permission:    Array of permissions to check for this subsection.

bool   enabled:       Should this subsection be accessible?

bool   is_default:    Is this the default subaction? If no subsection is
                      set as the default, the first one will be used.

The $options parameter for the constructor is an array that can contain some some combination of the following:

string action:        The action for this menu. If this is not set, it
                      will be determined automatically.

string current_area:  The currently selected area. If this is not set, it
                      will be determined automatically.

string base_url:      The base URL for items in this menu. If this is not
                      set, it will be determined automatically.

string template_name: The theme template to load for this menu.

string layer_name:    The template layer to load for this menu.

bool   do_big_icons:  If true, get large icons for admin home page.

array  extra_url_parameters:
                      Key-value pairs of extra parameters to append to
                      the menu item URLs.

bool   disable_url_session_check:
                      If true, does not append the session parameter to
                      the menu item URLs.

bool   disable_hook_call:
                      If true, skips the integrate_{action}_areas hook.

Table of Contents

Interfaces

ArrayAccess

Properties

$base_url  : string
$current_action  : string
$current_area  : string
$current_section  : string
$current_subsection  : string
$extra_parameters  : string
$id  : int
$include_data  : array<string|int, mixed>
$layer_name  : string
$loaded  : array<string|int, mixed>
$max_id  : int
$name  : string
$sections  : array<string|int, mixed>
$tab_data  : array<string|int, mixed>
$template_name  : string
$backup_area  : string
$data  : array<string|int, mixed>
$found_section  : bool
$options  : array<string|int, mixed>
$backcompat  : array<string|int, mixed>

Methods

__construct()  : mixed
Constructor.
create()  : array<string|int, mixed>|false
Static wrapper for constructor.
destroy()  : void
Delete a menu.
exportStatic()  : void
Provides a way to export a class's public static properties and methods to global namespace.
offsetExists()  : bool
Checks whether a property has been set when object is accessed as an array.
offsetGet()  : mixed
Gets properties when object is accessed as an array.
offsetSet()  : void
Sets properties when object is accessed as an array.
offsetUnset()  : void
Unsets properties when object is accessed as an array.
buildArea()  : void
Build the data array for an area of the menu.
buildExtraParameters()  : void
Build a list of additional parameters that should go in the URL.
buildSection()  : void
Build the data array for a section of the menu.
buildSubsection()  : void
Build the data array for a subsection of the menu.
checkBaseUrl()  : void
Goes through all the sections to check if the base menu has an url.
enabledAndAllowed()  : bool
Checks whether the given menu item is enabled and whether the current user has permission to access it.
setAreaIcon()  : void
Sets the icon for an area.
setCurrentSectionAndArea()  : void
Figures out which section and area the user is currently viewing.
setSelected()  : void
Figures out which section, area, and subsection are currently selected.

Properties

$base_url

public string $base_url

Base URL for the menu's buttons.

$current_action

public string $current_action = ''

The action that the user is currently viewing.

This corresponds to the 'action=...' URL parameter.

$current_area

public string $current_area = ''

The area within the action that the user is currently viewing.

This corresponds to the 'area=...' URL parameter.

$current_section

public string $current_section = ''

The section of the menu that the current area is in.

This does not correspond to an URL parameter. It is just a way of organizing the areas within the action.

$current_subsection

public string $current_subsection = ''

The subsection within the area that the user is currently viewing.

This corresponds to the 'sa=...' URL parameter.

$extra_parameters

public string $extra_parameters = ''

Extra URL parameters that should be appended to menu item links.

Typically this contains the session parameter, if anything.

$id

public int $id

ID number of this menu.

$include_data

public array<string|int, mixed> $include_data = []

Data about files to include, functions to call, etc., in order to make the current area work.

$layer_name

public string $layer_name

The template layer to load for this menu.

$loaded

public static array<string|int, mixed> $loaded = []

All loaded instances of this class. Keys are action names.

$max_id

public static int $max_id = 0

The highest $id value that has been assigned to a menu thus far.

$name

public string $name = ''

Generic name of this menu. Simply takes the form: 'menu_data_' . $id Used to provide a unique key in Utils::$context.

$sections

public array<string|int, mixed> $sections = []

The constructed hierarchical menu data.

$tab_data

public array<string|int, mixed> $tab_data = []

A set of tab buttons to show in a secondary menu below the main menu.

This is intended for more complex menus. The tab buttons typically (but not always) correspond to the menu items in the current subsection.

$template_name

public string $template_name

The theme template to load for this menu.

$backup_area

protected string $backup_area

Fallback area to show if $current_area can't be shown.

$data

protected array<string|int, mixed> $data = []

Holds the $data parameter passed to the constructor.

$found_section

protected bool $found_section = false

Whether we have found the current section yet.

Used while we are building the menu's sections.

$options

protected array<string|int, mixed> $options = []

Holds the $options parameter passed to the constructor.

$backcompat

private static array<string|int, mixed> $backcompat = ['func_names' => ['create' => 'createMenu', 'destroy' => 'destroyMenu']]

BackwardCompatibility settings for this class.

Methods

__construct()

Constructor.

public __construct(array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$data : array<string|int, mixed>

An array of menu data.

$options : array<string|int, mixed> = []

An array of menu options.

create()

Static wrapper for constructor.

public static create(array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>|false
Parameters
$data : array<string|int, mixed>

An array of menu data.

$options : array<string|int, mixed> = []

An array of menu options.

Return values
array<string|int, mixed>|false

Info about the selected menu item, or false if nothing to show.

destroy()

Delete a menu.

public static destroy([int|string $id = 'last' ]) : void
Parameters
$id : int|string = 'last'

The ID of a menu, or 'last' for the most recent one.

exportStatic()

Provides a way to export a class's public static properties and methods to global namespace.

public static exportStatic() : void

To do so:

  1. Use this trait in the class.
  2. At the END of the class's file, call its exportStatic() method.

Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.

Regarding the $backcompat items:

A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].

$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.

$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.

Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.

offsetExists()

Checks whether a property has been set when object is accessed as an array.

public offsetExists(mixed $prop) : bool
Parameters
$prop : mixed

The property name.

Return values
bool

offsetGet()

Gets properties when object is accessed as an array.

public offsetGet(mixed $prop) : mixed
Parameters
$prop : mixed

The property name.

offsetSet()

Sets properties when object is accessed as an array.

public offsetSet(mixed $prop, mixed $value) : void
Parameters
$prop : mixed

The property name.

$value : mixed

The value to set.

offsetUnset()

Unsets properties when object is accessed as an array.

public offsetUnset(mixed $prop) : void
Parameters
$prop : mixed

The property name.

buildArea()

Build the data array for an area of the menu.

protected buildArea(mixed $area) : void
Parameters
$area : mixed

buildExtraParameters()

Build a list of additional parameters that should go in the URL.

protected buildExtraParameters() : void

buildSection()

Build the data array for a section of the menu.

protected buildSection(mixed $section) : void
Parameters
$section : mixed

buildSubsection()

Build the data array for a subsection of the menu.

protected buildSubsection(mixed $subsection) : void
Parameters
$subsection : mixed

checkBaseUrl()

Goes through all the sections to check if the base menu has an url.

protected checkBaseUrl() : void

enabledAndAllowed()

Checks whether the given menu item is enabled and whether the current user has permission to access it.

protected enabledAndAllowed(mixed $menu_item) : bool
Parameters
$menu_item : mixed
Return values
bool

setAreaIcon()

Sets the icon for an area.

protected setAreaIcon(mixed $area) : void
Parameters
$area : mixed

setCurrentSectionAndArea()

Figures out which section and area the user is currently viewing.

protected setCurrentSectionAndArea() : void

setSelected()

Figures out which section, area, and subsection are currently selected.

protected setSelected() : void

        
On this page

Search results