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

Data structure representing a simple form with only one button. More...

Inheritance diagram for single_button:
renderable enrol_user_button gradereport_history\output\user_button

Public Member Functions

 __construct (moodle_url $url, $label, $method='post', $type=self::BUTTON_SECONDARY, $attributes=[])
 Constructor.
 
 __get ($name)
 Magic method getter.
 
 __set ($name, $value)
 Magic setter method.
 
 add_action (component_action $action)
 Add action to the button.
 
 add_confirm_action ($confirmmessage)
 Shortcut for adding a JS confirm dialog when the button is clicked.
 
 export_for_template (renderer_base $output)
 Export data.
 
 set_attribute ($name, $value)
 Sets an attribute for the HTML button tag.
 

Public Attributes

string $actionid
 Action id.
 
array $actions = array()
 List of attached actions.
 
string $class = 'singlebutton'
 Wrapping div class.
 
bool $disabled = false
 True if button disabled, false if normal.
 
string $formid
 Form id.
 
string $label
 Button label.
 
string $method = 'post'
 Form submit method post or get.
 
array $params
 $params URL Params
 
string $tooltip = null
 Button tooltip.
 
moodle_url $url
 Target url.
 
const BUTTON_DANGER = 'danger'
 Possible button types - Danger.
 
const BUTTON_INFO = 'info'
 Possible button types - Info.
 
const BUTTON_PRIMARY = 'primary'
 Possible button types - Primary.
 
const BUTTON_SECONDARY = 'secondary'
 Possible button types - Secondary.
 
const BUTTON_SUCCESS = 'success'
 Possible button types - Success.
 
const BUTTON_TYPES
 Possible button types.
 
const BUTTON_WARNING = 'warning'
 Possible button types - Warning.
 

Protected Attributes

array $attributes = []
 
string $type
 Type of button (from defined types).
 

Detailed Description

Data structure representing a simple form with only one button.

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

Constructor & Destructor Documentation

◆ __construct()

single_button::__construct ( moodle_url $url,
$label,
$method = 'post',
$type = self::BUTTON_SECONDARY,
$attributes = [] )

Constructor.

Parameters
moodle_url$url
string$labelbutton text
string$methodget or post submit method
string$typewhether this is a primary button or another type, used for styling
array$attributesAttributes for the HTML button tag

Member Function Documentation

◆ __get()

single_button::__get ( $name)

Magic method getter.

This method manages access to some properties and will display deprecation message when accessing 'primary' property.

Parameters
string$name
Return values
mixed

◆ __set()

single_button::__set ( $name,
$value )

Magic setter method.

This method manages access to some properties and will display deprecation message when accessing 'primary' property.

Parameters
string$name
mixed$value

◆ add_action()

single_button::add_action ( component_action $action)

Add action to the button.

Parameters
component_action$action

◆ add_confirm_action()

single_button::add_confirm_action ( $confirmmessage)

Shortcut for adding a JS confirm dialog when the button is clicked.

The message must be a yes/no question.

Parameters
string$confirmmessageThe yes/no confirmation question. If "Yes" is clicked, the original action will occur.

◆ export_for_template()

single_button::export_for_template ( renderer_base $output)

Export data.

Parameters
renderer_base$outputRenderer.
Return values
stdClass

◆ set_attribute()

single_button::set_attribute ( $name,
$value )

Sets an attribute for the HTML button tag.

Parameters
string$nameThe attribute name
mixed$valueThe value
Return values
null

Member Data Documentation

◆ $type

string single_button::$type
protected

Type of button (from defined types).

Used for styling.

◆ BUTTON_TYPES

const single_button::BUTTON_TYPES
Initial value:
= [
self::BUTTON_PRIMARY,
self::BUTTON_SECONDARY,
self::BUTTON_SUCCESS,
self::BUTTON_DANGER,
self::BUTTON_WARNING,
self::BUTTON_INFO
]

Possible button types.

From boostrap.


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