Skip to content

Commit 8edfcf6

Browse files
committed
Applied hotfix patch from openLMS snap repo
1 parent edae95f commit 8edfcf6

File tree

6 files changed

+9579
-24
lines changed

6 files changed

+9579
-24
lines changed

theme/snap/classes/output/core_renderer.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
defined('MOODLE_INTERNAL') || die();
2828
require_once($CFG->dirroot.'/message/output/popup/lib.php');
2929

30+
use core\output\mustache_template_finder;
31+
use core\output\templatable;
3032
use stdClass;
3133
use context_course;
3234
use context_system;
@@ -3116,4 +3118,85 @@ protected function snap_page_is_whitelisted_mod() {
31163118
return $this->page->context->contextlevel === CONTEXT_MODULE
31173119
&& in_array($this->page->cm->modname, $whitelist);
31183120
}
3121+
3122+
/**
3123+
* Renders an mform element from a template.
3124+
*
3125+
* Copied from core_renderer::mform_element() to allow injecting
3126+
* extra context variables specific to certain modules (e.g., mod_feedback).
3127+
*
3128+
* @param HTML_QuickForm_element $element element
3129+
* @param bool $required if input is required field
3130+
* @param bool $advanced if input is an advanced field
3131+
* @param string $error error message to display
3132+
* @param bool $ingroup True if this element is rendered as part of a group
3133+
* @return mixed string|bool
3134+
*/
3135+
public function mform_element($element, $required, $advanced, $error, $ingroup) {
3136+
$templatename = 'core_form/element-' . $element->getType();
3137+
if ($ingroup) {
3138+
$templatename .= "-inline";
3139+
}
3140+
try {
3141+
// We call this to generate a file not found exception if there is no template.
3142+
// We don't want to call export_for_template if there is no template.
3143+
mustache_template_finder::get_template_filepath($templatename);
3144+
3145+
if ($element instanceof templatable) {
3146+
$elementcontext = $element->export_for_template($this);
3147+
3148+
$helpbutton = '';
3149+
if (method_exists($element, 'getHelpButton')) {
3150+
$helpbutton = $element->getHelpButton();
3151+
}
3152+
$label = $element->getLabel();
3153+
$text = '';
3154+
if (method_exists($element, 'getText')) {
3155+
// There currently exists code that adds a form element with an empty label.
3156+
// If this is the case then set the label to the description.
3157+
if (empty($label)) {
3158+
$label = $element->getText();
3159+
} else {
3160+
$text = $element->getText();
3161+
}
3162+
}
3163+
3164+
// Generate the form element wrapper ids and names to pass to the template.
3165+
// This differs between group and non-group elements.
3166+
if ($element->getType() === 'group') {
3167+
// Group element.
3168+
// The id will be something like 'fgroup_id_NAME'. E.g. fgroup_id_mygroup.
3169+
$elementcontext['wrapperid'] = $elementcontext['id'];
3170+
3171+
// Ensure group elements pass through the group name as the element name.
3172+
$elementcontext['name'] = $elementcontext['groupname'];
3173+
} else {
3174+
// Non grouped element.
3175+
// Creates an id like 'fitem_id_NAME'. E.g. fitem_id_mytextelement.
3176+
$elementcontext['wrapperid'] = 'fitem_' . $elementcontext['id'];
3177+
}
3178+
3179+
// Detect if we are in a feedback module
3180+
global $SCRIPT;
3181+
$isfeedbackform = strpos($SCRIPT, '/mod/feedback/') !== false;
3182+
$elementcontext['isfeedbackform'] = $isfeedbackform;
3183+
3184+
$context = [
3185+
'element' => $elementcontext,
3186+
'label' => $label,
3187+
'text' => $text,
3188+
'required' => $required,
3189+
'advanced' => $advanced,
3190+
'helpbutton' => $helpbutton,
3191+
'error' => $error,
3192+
];
3193+
3194+
return $this->render_from_template($templatename, $context);
3195+
}
3196+
} catch (\Exception $e) {
3197+
// No template for this element.
3198+
return false;
3199+
}
3200+
}
3201+
31193202
}

0 commit comments

Comments
 (0)