|
18 | 18 |
|
19 | 19 | defined('MOODLE_INTERNAL') || die();
|
20 | 20 |
|
| 21 | +use mod_cms\local\model\cms; |
| 22 | +use mod_cms\local\renderer; |
| 23 | + |
21 | 24 | require_once($CFG->dirroot . '/mod/cms/lib.php');
|
22 | 25 |
|
23 | 26 | /**
|
@@ -95,7 +98,6 @@ public function get_document_recordset($modifiedfrom = 0, \context $context = nu
|
95 | 98 | * @return \core_search\document
|
96 | 99 | */
|
97 | 100 | public function get_document($record, $options = []) {
|
98 |
| - global $DB; |
99 | 101 | try {
|
100 | 102 | $cm = $this->get_cm('cms', $record->id, $record->courseid);
|
101 | 103 | $context = \context_module::instance($cm->id);
|
@@ -130,9 +132,21 @@ public function get_document($record, $options = []) {
|
130 | 132 | $value = $record->value;
|
131 | 133 | $valueformat = $record->valueformat;
|
132 | 134 | }
|
| 135 | + |
133 | 136 | // Add mustache template to value.
|
134 | 137 | if (!empty($defaultvalues[$record->typeid]->mustache)) {
|
135 |
| - $value .= ' ' . $defaultvalues[$record->typeid]->mustache; |
| 138 | + $cms = new cms($cm->instance); |
| 139 | + $renderer = new renderer($cms); |
| 140 | + ob_start(); |
| 141 | + try { |
| 142 | + // Indexer uses "Empty" session, it may get an error from rendering. |
| 143 | + $value .= $renderer->get_html(); |
| 144 | + } catch (\Exception $e) { |
| 145 | + // Use template when an error occurs. |
| 146 | + $value .= ' ' . $defaultvalues[$record->typeid]->mustache; |
| 147 | + } |
| 148 | + // Do not show any errors from rendering. |
| 149 | + ob_end_clean(); |
136 | 150 | if (empty($title)) {
|
137 | 151 | $title = $defaultvalues[$record->typeid]->name;
|
138 | 152 | }
|
|
0 commit comments