diff --git a/grade/edit/outcome/edit_form.php b/grade/edit/outcome/edit_form.php index ae4bacd6bc9..fd06079b809 100644 --- a/grade/edit/outcome/edit_form.php +++ b/grade/edit/outcome/edit_form.php @@ -49,12 +49,8 @@ class edit_outcome_form extends moodleform { $options = array(); - $mform->addElement('select', 'scaleid', get_string('scale'), $options); - - $url = new moodle_url('/grade/edit/scale/edit.php', array('courseid' => $COURSE->id)); - $label = get_string('scalescustomcreate'); - $mform->addElement('static', 'scaleidlink', '', html_writer::link($url, $label)); - + $mform->addElement('selectwithlink', 'scaleid', get_string('scale'), $options, null, + array('link' => $CFG->wwwroot.'/grade/edit/scale/edit.php?courseid='.$COURSE->id, 'label' => get_string('scalescustomcreate'))); $mform->addHelpButton('scaleid', 'typescale', 'grades'); $mform->addRule('scaleid', get_string('required'), 'required'); diff --git a/grade/edit/tree/outcomeitem_form.php b/grade/edit/tree/outcomeitem_form.php index 5930ca768b3..285acbed4c3 100644 --- a/grade/edit/tree/outcomeitem_form.php +++ b/grade/edit/tree/outcomeitem_form.php @@ -56,11 +56,8 @@ class edit_outcomeitem_form extends moodleform { $options[$outcome->id] = $outcome->get_name(); } } - $url = new moodle_url('/grade/edit/outcome/course.php', array('id' => $COURSE->id)); - $label = get_string('outcomeassigntocourse', 'grades'); - - $mform->addElement('select', 'outcomeid', get_string('outcome', 'grades'), $options); - $mform->addElement('static', 'outcomeidlink', '', html_writer::link($url, $label)); + $mform->addElement('selectwithlink', 'outcomeid', get_string('outcome', 'grades'), $options, null, + array('link' => $CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$COURSE->id, 'label' => get_string('outcomeassigntocourse', 'grades'))); $mform->addHelpButton('outcomeid', 'outcome', 'grades'); $mform->addRule('outcomeid', get_string('required'), 'required'); diff --git a/lib/form/editor.php b/lib/form/editor.php index 204931688ac..0488286fbdf 100644 --- a/lib/form/editor.php +++ b/lib/form/editor.php @@ -415,12 +415,12 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element implements templatab $context['value'] = $text; $context['format'] = $format; - $str .= $OUTPUT->render_from_template('core_form/editor_textarea', $context); - if (!is_null($this->getAttribute('onblur')) && !is_null($this->getAttribute('onchange'))) { $context['changelistener'] = true; } + $str .= $OUTPUT->render_from_template('core_form/editor_textarea', $context); + // during moodle installation, user area doesn't exist // so we need to disable filepicker here. if (!during_initial_install() && empty($CFG->adminsetuppending)) { diff --git a/lib/form/selectwithlink.php b/lib/form/selectwithlink.php index eb2a0d07fe5..1643e6f383e 100644 --- a/lib/form/selectwithlink.php +++ b/lib/form/selectwithlink.php @@ -26,6 +26,7 @@ */ require_once('HTML/QuickForm/select.php'); +require_once('templatable_form_element.php'); /** * select type form element @@ -38,7 +39,11 @@ require_once('HTML/QuickForm/select.php'); * @copyright 2008 Nicolas Connault * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class MoodleQuickForm_selectwithlink extends HTML_QuickForm_select{ +class MoodleQuickForm_selectwithlink extends HTML_QuickForm_select implements templatable { + + use templatable_form_element { + export_for_template as export_for_template_base; + } /** @var string html for help button, if empty then no help */ var $_helpbutton=''; @@ -64,7 +69,6 @@ class MoodleQuickForm_selectwithlink extends HTML_QuickForm_select{ * @param bool $linkdata data to be posted */ public function __construct($elementName=null, $elementLabel=null, $options=null, $attributes=null, $linkdata=null) { - debugging('Element type selectwithlink is deprecated. Use 2 elements.', DEBUG_DEVELOPER); if (!empty($linkdata['link']) && !empty($linkdata['label'])) { $this->_link = $linkdata['link']; $this->_linklabel = $linkdata['label']; @@ -75,6 +79,8 @@ class MoodleQuickForm_selectwithlink extends HTML_QuickForm_select{ } parent::__construct($elementName, $elementLabel, $options, $attributes); + + $this->_type = 'selectwithlink'; } /** @@ -220,4 +226,39 @@ class MoodleQuickForm_selectwithlink extends HTML_QuickForm_select{ return $this->_prepareValue($cleaned[0], $assoc); } } + + public function export_for_template(renderer_base $output) { + $context = $this->export_for_template_base($output); + + $options = []; + foreach ($this->_options as $option) { + if (is_array($this->_values) && in_array( (string) $option['attr']['value'], $this->_values)) { + $this->_updateAttrArray($option['attr'], ['selected' => 'selected']); + } + $o = [ + 'text' => $option['text'], + 'value' => $option['attr']['value'], + 'selected' => !empty($option['attr']['selected']) + ]; + $options[] = $o; + } + $context['options'] = $options; + if (!empty($this->_link)) { + if (!empty($this->_linkreturn) && is_array($this->_linkreturn)) { + $appendchar = '?'; + if (strstr($this->_link, '?')) { + $appendchar = '&'; + } + + foreach ($this->_linkreturn as $key => $val) { + $this->_link .= $appendchar."$key=$val"; + $appendchar = '&'; + } + } + } + $context['link'] = $this->_link; + $context['linklabel'] = $this->_linklabel; + + return $context; + } } diff --git a/theme/noname/templates/core/form_autocomplete_selection.mustache b/theme/noname/templates/core/form_autocomplete_selection.mustache index 16f5010079c..6bd2348b7dd 100644 --- a/theme/noname/templates/core/form_autocomplete_selection.mustache +++ b/theme/noname/templates/core/form_autocomplete_selection.mustache @@ -48,4 +48,3 @@ {{noSelectionString}} {{/items}} - diff --git a/theme/noname/templates/core_form/element-password.mustache b/theme/noname/templates/core_form/element-password.mustache index 3c0b252f6f2..8d6d191ef56 100644 --- a/theme/noname/templates/core_form/element-password.mustache +++ b/theme/noname/templates/core_form/element-password.mustache @@ -16,8 +16,8 @@ require(['core/yui'], function(Y) { Y.use('moodle-form-passwordunmask', function() { M.form.passwordunmask({ formid: {{#quote}}{{element.id}}{{/quote}}, - checkboxlabel: '{{#str}}unmaskpassword, form{{/str}}', + checkboxlabel: {{#quote}}{{#str}}unmaskpassword, form{{/str}}{{/quote}}, checkboxname: {{#quote}}{{element.name}}{{/quote}} }); }); }); -{{/js}} \ No newline at end of file +{{/js}} diff --git a/theme/noname/templates/core_form/element-selectwithlink.mustache b/theme/noname/templates/core_form/element-selectwithlink.mustache new file mode 100644 index 00000000000..5731fec75ec --- /dev/null +++ b/theme/noname/templates/core_form/element-selectwithlink.mustache @@ -0,0 +1,17 @@ +{{< core_form/element-template }} + {{$element}} + + {{element.linklabel}} + {{/element}} +{{/ core_form/element-template }}