mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-59740 core_form: add ability to specify if a button is primary
This commit is contained in:
parent
8146b1f06d
commit
a91a4dd77b
1 changed files with 17 additions and 4 deletions
|
@ -43,15 +43,28 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
|
||||||
export_for_template as export_for_template_base;
|
export_for_template as export_for_template_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool $primary Is this button a primary button?
|
||||||
|
*/
|
||||||
|
protected $primary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
*
|
*
|
||||||
* @param string $elementName (optional) name of the field
|
* @param string $elementName (optional) name of the field
|
||||||
* @param string $value (optional) field label
|
* @param string $value (optional) field label
|
||||||
* @param string $attributes (optional) Either a typical HTML attribute string or an associative array
|
* @param string $attributes (optional) Either a typical HTML attribute string or an associative array
|
||||||
|
* @param bool|null $primary Is this button a primary button?
|
||||||
*/
|
*/
|
||||||
public function __construct($elementName=null, $value=null, $attributes=null) {
|
public function __construct($elementName=null, $value=null, $attributes=null, $primary = null) {
|
||||||
parent::__construct($elementName, $value, $attributes);
|
parent::__construct($elementName, $value, $attributes);
|
||||||
|
|
||||||
|
// Fallback to legacy behaviour if no value specified.
|
||||||
|
if (is_null($primary)) {
|
||||||
|
$this->primary = $this->getName() != 'cancel';
|
||||||
|
} else {
|
||||||
|
$this->primary = $primary;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,9 +72,9 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
|
||||||
*
|
*
|
||||||
* @deprecated since Moodle 3.1
|
* @deprecated since Moodle 3.1
|
||||||
*/
|
*/
|
||||||
public function MoodleQuickForm_submit($elementName=null, $value=null, $attributes=null) {
|
public function MoodleQuickForm_submit($elementName=null, $value=null, $attributes=null, $primary = null) {
|
||||||
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
|
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
|
||||||
self::__construct($elementName, $value, $attributes);
|
self::__construct($elementName, $value, $attributes, $primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,7 +128,7 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
|
||||||
|
|
||||||
public function export_for_template(renderer_base $output) {
|
public function export_for_template(renderer_base $output) {
|
||||||
$context = $this->export_for_template_base($output);
|
$context = $this->export_for_template_base($output);
|
||||||
if ($this->getName() == 'cancel') {
|
if (!$this->primary) {
|
||||||
$context['secondary'] = true;
|
$context['secondary'] = true;
|
||||||
}
|
}
|
||||||
return $context;
|
return $context;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue