mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-62191 output: New extra attributes for single_button
Useful for data- attributes.
This commit is contained in:
parent
9528b1ff5b
commit
ca81e906e0
4 changed files with 36 additions and 3 deletions
|
@ -867,17 +867,24 @@ class single_button implements renderable {
|
|||
*/
|
||||
public $actionid;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param moodle_url $url
|
||||
* @param string $label button text
|
||||
* @param string $method get or post submit method
|
||||
* @param array $attributes Attributes for the HTML button tag
|
||||
*/
|
||||
public function __construct(moodle_url $url, $label, $method='post', $primary=false) {
|
||||
public function __construct(moodle_url $url, $label, $method='post', $primary=false, $attributes = []) {
|
||||
$this->url = clone($url);
|
||||
$this->label = $label;
|
||||
$this->method = $method;
|
||||
$this->primary = $primary;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -898,6 +905,17 @@ class single_button implements renderable {
|
|||
$this->actions[] = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an attribute for the HTML button tag.
|
||||
*
|
||||
* @param string $name The attribute name
|
||||
* @param mixed $value The value
|
||||
* @return null
|
||||
*/
|
||||
public function set_attribute($name, $value) {
|
||||
$this->attributes[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export data.
|
||||
*
|
||||
|
@ -918,6 +936,11 @@ class single_button implements renderable {
|
|||
$data->tooltip = $this->tooltip;
|
||||
$data->primary = $this->primary;
|
||||
|
||||
$data->attributes = [];
|
||||
foreach ($this->attributes as $key => $value) {
|
||||
$data->attributes[] = ['name' => $key, 'value' => $value];
|
||||
}
|
||||
|
||||
// Form parameters.
|
||||
$params = $this->url->params();
|
||||
if ($this->method === 'post') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue