From 6fb3230e5421eadb229926d5ee7f001073e252db Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 12 Dec 2016 20:05:44 +0800 Subject: [PATCH] #52 Fixed appearance of colour picker in Boost --- includes/colourpicker.php | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/includes/colourpicker.php b/includes/colourpicker.php index 6043d0f..16585a5 100644 --- a/includes/colourpicker.php +++ b/includes/colourpicker.php @@ -16,7 +16,8 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -require_once("HTML/QuickForm/text.php"); +require_once($CFG->dirroot . '/lib/form/editor.php'); +require_once($CFG->dirroot . '/lib/form/templatable_form_element.php'); /** * Form element for handling the colour picker. @@ -25,7 +26,10 @@ require_once("HTML/QuickForm/text.php"); * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class MoodleQuickForm_customcert_colourpicker extends HTML_QuickForm_text { +class MoodleQuickForm_customcert_colourpicker extends MoodleQuickForm_editor { + use templatable_form_element { + export_for_template as export_for_template_base; + } /** * The string for the help icon, if empty then no help icon will be displayed. @@ -39,7 +43,7 @@ class MoodleQuickForm_customcert_colourpicker extends HTML_QuickForm_text { * @param string $elementLabel * @param array $attributes */ - function __construct($elementName = null, $elementLabel = null, $attributes = null) { + public function __construct($elementName = null, $elementLabel = null, $attributes = null) { parent::__construct($elementName, $elementLabel, $attributes); } @@ -50,10 +54,24 @@ class MoodleQuickForm_customcert_colourpicker extends HTML_QuickForm_text { * @param string $elementLabel * @param array $attributes */ - function MoodleQuickForm_customcert_colourpicker($elementName = null, $elementLabel = null, $attributes = null) { + public function MoodleQuickForm_customcert_colourpicker($elementName = null, $elementLabel = null, $attributes = null) { self::__construct($elementName, $elementLabel, $attributes); } + /** + * Sets the value of the form element + */ + public function setValue($value) { + $this->updateAttributes(array('value' => $value)); + } + + /** + * Gets the value of the form element + */ + public function getValue() { + return $this->getAttribute('value'); + } + /** * Returns the html string to display this element. * @@ -82,4 +100,11 @@ class MoodleQuickForm_customcert_colourpicker extends HTML_QuickForm_text { public function getHelpButton(){ return $this->_helpbutton; } + + public function export_for_template(renderer_base $output) { + $context = $this->export_for_template_base($output); + $context['html'] = $this->toHtml(); + + return $context; + } }