Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
action_menu Class Reference

An action menu. More...

Inheritance diagram for action_menu:
renderable templatable

Public Member Functions

 __construct (array $actions=array())
 Constructs the action menu with the given items.
 
 add ($action)
 Adds an action to this action menu.
 
 add_primary_action ($action)
 Adds a primary action to the action menu.
 
 add_secondary_action ($action)
 Adds a secondary action to the action menu.
 
 add_secondary_subpanel (subpanel $subpanel)
 Adds a secondary subpanel.
 
 do_not_enhance ()
 If you call this method the action menu will be displayed but will not be enhanced.
 
 export_for_template (renderer_base $output)
 Export for template.
 
 get_primary_actions (core_renderer $output=null)
 Returns the primary actions ready to be rendered.
 
 get_secondary_actions ()
 Returns the secondary actions ready to be rendered.
 
 initialise_js (moodle_page $page)
 Initialises JS required fore the action menu.
 
 is_empty ()
 Return true if there is at least one visible link in the menu.
 
 set_action_label ($label)
 Sets the label for the menu trigger.
 
 set_additional_classes (string $class='')
 Add classes to the action menu for an easier styling.
 
 set_alignment ($dialogue, $button)
 Sets the alignment of the dialogue in relation to button used to toggle it.
 
 set_boundary (string $boundary)
 Set the overflow constraint boundary of the dropdown menu.
 
 set_constraint ($ancestorselector)
 Sets a constraint for the dialogue.
 
 set_kebab_trigger (?string $triggername=null, ?core_renderer $output=null, ?string $extraclasses='')
 Setup trigger as in the kebab menu.
 
 set_menu_left ()
 Aligns the left corner of the dropdown.
 
 set_menu_trigger ($trigger, $extraclasses='')
 Sets the menu trigger text.
 
 set_nowrap_on_items ($value=true)
 Sets nowrap on items.
 
 set_owner_selector ($selector)
 Sets the selector that should be used to find the owning node of this menu.
 
 will_be_enhanced ()
 Returns true if this action menu will be enhanced.
 

Public Attributes

pix_icon $actionicon
 An icon to use for the toggling the secondary menu (dropdown).
 
array $actionlabel = null
 The string to use for the accessible label for the menu.
 
array $actiontext = null
 The string to use next to the icon for the action icon relating to the secondary (dropdown) menu.
 
array $attributes = array()
 An array of attributes added to the container of the action menu.
 
array $attributesprimary = array()
 An array of attributes added to the container of the primary actions.
 
array $attributessecondary = array()
 An array of attributes added to the container of the secondary actions.
 
string $dropdownalignment = ''
 Dropdown menu alignment class.
 
string $menutrigger = ''
 Any text to use for the toggling the secondary menu (dropdown).
 
bool $prioritise = false
 Place the action menu before all other actions.
 
array $triggerattributes = []
 An array of attributes added to the trigger element of the secondary menu.
 
string $triggerextraclasses = ''
 Any extra classes for toggling to the secondary menu.
 
const BL = 3
 Top right alignment.
 
const BR = 4
 Top right alignment.
 
const DEFAULT_KEBAB_TRIGGER_CLASSES = 'btn btn-icon d-flex align-items-center justify-content-center no-caret'
 Classes for the trigger menu.
 
const TL = 1
 Top right alignment.
 
const TR = 2
 Top right alignment.
 

Protected Member Functions

 export_primary_actions_for_template (renderer_base $output)
 Export the primary actions for the template.
 
 export_secondary_actions_for_template (renderer_base $output)
 Export the secondary actions for the template.
 
 get_align_string ($align)
 Returns a string to describe the alignment.
 

Protected Attributes

int $instance = 0
 The instance number.
 
array $primaryactions = array()
 An array of primary actions.
 
array $secondaryactions = array()
 An array of secondary actions.
 

Detailed Description

An action menu.

This action menu component takes a series of primary and secondary actions. The primary actions are displayed permanently and the secondary attributes are displayed within a drop down menu.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

action_menu::__construct ( array $actions = array())

Constructs the action menu with the given items.

Parameters
array$actionsAn array of actions (action_menu_link|pix_icon|string).

Member Function Documentation

◆ add()

action_menu::add ( $action)

Adds an action to this action menu.

Parameters
action_link | pix_icon | subpanel | string$action

◆ add_primary_action()

action_menu::add_primary_action ( $action)

Adds a primary action to the action menu.

Parameters
action_menu_link | action_link | pix_icon | string$action

◆ add_secondary_action()

action_menu::add_secondary_action ( $action)

Adds a secondary action to the action menu.

Parameters
action_link | pix_icon | string$action

◆ add_secondary_subpanel()

action_menu::add_secondary_subpanel ( subpanel $subpanel)

Adds a secondary subpanel.

Parameters
subpanel$subpanel

◆ do_not_enhance()

action_menu::do_not_enhance ( )

If you call this method the action menu will be displayed but will not be enhanced.

By not displaying the menu enhanced all items will be displayed in a single row.

Deprecated
since Moodle 3.2

◆ export_for_template()

action_menu::export_for_template ( renderer_base $output)

Export for template.

Parameters
renderer_base$outputThe renderer.
Return values
stdClass

Implements templatable.

◆ export_primary_actions_for_template()

action_menu::export_primary_actions_for_template ( renderer_base $output)
protected

Export the primary actions for the template.

Parameters
renderer_base$output
Return values
stdClass

◆ export_secondary_actions_for_template()

action_menu::export_secondary_actions_for_template ( renderer_base $output)
protected

Export the secondary actions for the template.

Parameters
renderer_base$output
Return values
stdClass

◆ get_align_string()

action_menu::get_align_string ( $align)
protected

Returns a string to describe the alignment.

Parameters
int$alignOne of action_menu\TL, action_menu\TR, action_menu\BL, action_menu\BR.
Return values
string

◆ get_primary_actions()

action_menu::get_primary_actions ( core_renderer $output = null)

Returns the primary actions ready to be rendered.

Parameters
core_renderer$outputThe renderer to use for getting icons.
Return values
array

◆ get_secondary_actions()

action_menu::get_secondary_actions ( )

Returns the secondary actions ready to be rendered.

Return values
array

◆ initialise_js()

action_menu::initialise_js ( moodle_page $page)

Initialises JS required fore the action menu.

The JS is only required once as it manages all action menu's on the page.

Parameters
moodle_page$page

◆ is_empty()

action_menu::is_empty ( )

Return true if there is at least one visible link in the menu.

Return values
bool

◆ set_action_label()

action_menu::set_action_label ( $label)

Sets the label for the menu trigger.

Parameters
string$labelThe text

◆ set_additional_classes()

action_menu::set_additional_classes ( string $class = '')

Add classes to the action menu for an easier styling.

Parameters
string$classThe class to add to attributes.

◆ set_alignment()

action_menu::set_alignment ( $dialogue,
$button )

Sets the alignment of the dialogue in relation to button used to toggle it.

Deprecated
since Moodle 4.0
Parameters
int$dialogueOne of action_menu\TL, action_menu\TR, action_menu\BL, action_menu\BR.
int$buttonOne of action_menu\TL, action_menu\TR, action_menu\BL, action_menu\BR.

◆ set_boundary()

action_menu::set_boundary ( string $boundary)

Set the overflow constraint boundary of the dropdown menu.

See also
https://getbootstrap.com/docs/4.6/components/dropdowns/#options The 'boundary' option in the Bootstrap documentation
Parameters
string$boundaryAccepts the values of 'viewport', 'window', or 'scrollParent'.
Exceptions
coding_exception

◆ set_constraint()

action_menu::set_constraint ( $ancestorselector)

Sets a constraint for the dialogue.

The constraint is applied when the dialogue is shown and limits the display of the dialogue to within the element the constraint identifies.

This is required whenever the action menu is displayed inside any CSS element with the .no-overflow class (flexible_table and any of it's child classes are a likely candidate).

Deprecated
since Moodle 4.3
Parameters
string$ancestorselectorA snippet of CSS used to identify the ancestor to contrain the dialogue to.

◆ set_kebab_trigger()

action_menu::set_kebab_trigger ( ?string $triggername = null,
?core_renderer $output = null,
?string $extraclasses = '' )

Setup trigger as in the kebab menu.

Parameters
string | null$triggername
core_renderer | null$output
string | null$extraclassesextra classes for the trigger {
See also
self\set_menu_trigger()}
Exceptions
coding_exception

◆ set_menu_trigger()

action_menu::set_menu_trigger ( $trigger,
$extraclasses = '' )

Sets the menu trigger text.

Parameters
string$triggerThe text
string$extraclassesExtra classes to style the secondary menu toggle.

◆ set_nowrap_on_items()

action_menu::set_nowrap_on_items ( $value = true)

Sets nowrap on items.

If true menu items should not wrap lines if they are longer than the available space.

This property can be useful when the action menu is displayed within a parent element that is either floated or relatively positioned. In that situation the width of the menu is determined by the width of the parent element which may not be large enough for the menu items without them wrapping. This disables the wrapping so that the menu takes on the width of the longest item.

Parameters
bool$valueIf true nowrap gets set, if false it gets removed. Defaults to true.

◆ set_owner_selector()

action_menu::set_owner_selector ( $selector)

Sets the selector that should be used to find the owning node of this menu.

Parameters
string$selectorA CSS/YUI selector to identify the owner of the menu.

◆ will_be_enhanced()

action_menu::will_be_enhanced ( )

Returns true if this action menu will be enhanced.

Return values
bool

Member Data Documentation

◆ $attributes

array action_menu::$attributes = array()

An array of attributes added to the container of the action menu.

Initialised with defaults during construction.

◆ $attributesprimary

array action_menu::$attributesprimary = array()

An array of attributes added to the container of the primary actions.

Initialised with defaults during construction.

◆ $attributessecondary

array action_menu::$attributessecondary = array()

An array of attributes added to the container of the secondary actions.

Initialised with defaults during construction.

◆ $instance

int action_menu::$instance = 0
protected

The instance number.

This is unique to this instance of the action menu.

◆ $primaryactions

array action_menu::$primaryactions = array()
protected

An array of primary actions.

Please use action_menu::add_primary_action() to add actions.

◆ $secondaryactions

array action_menu::$secondaryactions = array()
protected

An array of secondary actions.

Please use action_menu::add_secondary_action() to add actions.


The documentation for this class was generated from the following file: