. /** * This file contains the form element for handling the colour picker. * * @package mod_customcert * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); require_once($CFG->dirroot . '/lib/form/editor.php'); /** * Form element for handling the colour picker. * * @package mod_customcert * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class moodlequickform_customcert_colourpicker extends moodlequickform_editor { /** * Sets the value of the form element * * @param string $value */ 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. * * @return string */ public function tohtml() { global $PAGE, $OUTPUT; $PAGE->requires->js_init_call('M.util.init_colour_picker', array($this->getAttribute('id'), null)); $content = ''; $content .= html_writer::start_tag('div', array('class' => 'form-colourpicker defaultsnext')); $content .= html_writer::tag('div', $OUTPUT->pix_icon('i/loading', get_string('loading', 'admin'), 'moodle', array('class' => 'loadingicon')), array('class' => 'admin_colourpicker clearfix')); $content .= html_writer::empty_tag('input', array('type' => 'text', 'id' => $this->getAttribute('id'), 'name' => $this->getName(), 'value' => $this->getValue(), 'size' => '12')); $content .= html_writer::end_tag('div'); return $content; } /** * Function to export the renderer data in a format that is suitable for a mustache template. * * @param \renderer_base $output Used to do a final render of any components that need to be rendered for export. * @return \stdClass|array */ public function export_for_template(renderer_base $output) { $context = $this->export_for_template_base($output); $context['html'] = $this->toHtml(); return $context; } }