From e455d6f4830cd5b0ac3f197204f6f9858bbf7f82 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 27 Mar 2019 15:21:24 +0800 Subject: [PATCH] MDL-65069 core_form: Expose the form's submit's class attribute Exposed the submit button's class attribute so it can be overriden by custom classes provided by the programmer. --- lib/form/submit.php | 17 +++++++++++++++++ .../templates/element-submit-inline.mustache | 9 ++++++--- lib/form/templates/element-submit.mustache | 10 +++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/form/submit.php b/lib/form/submit.php index e40f457567c..23c1ff718f2 100644 --- a/lib/form/submit.php +++ b/lib/form/submit.php @@ -48,6 +48,13 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl */ protected $primary; + /** + * Any class apart from 'btn' would be override with this content + * + * @var string $customclassoverride Custom class override for the input element + */ + protected $customclassoverride; + /** * constructor * @@ -65,6 +72,12 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl } else { $this->primary = $primary; } + + $class = $this->getAttribute('customclassoverride'); + if ($class) { + $this->removeAttribute('customclassoverride'); + $this->customclassoverride = $class; + } } /** @@ -131,6 +144,10 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl if (!$this->primary) { $context['secondary'] = true; } + + if ($this->customclassoverride) { + $context['customclass'] = $this->customclassoverride; + } return $context; } } diff --git a/lib/form/templates/element-submit-inline.mustache b/lib/form/templates/element-submit-inline.mustache index 71158500d98..d576e572783 100644 --- a/lib/form/templates/element-submit-inline.mustache +++ b/lib/form/templates/element-submit-inline.mustache @@ -3,9 +3,12 @@ {{^element.frozen}}