MDL-34669: Fix editor filepicker context bt trying to use page context
authorKirill Astashov <kirill.astashov@netspot.com.au>
Mon, 6 Aug 2012 08:57:24 +0000 (16:57 +0800)
committerMarina Glancy <marina@moodle.com>
Mon, 6 Aug 2012 08:58:44 +0000 (16:58 +0800)
lib/form/editor.php

index 50d32ef..99ee930 100644 (file)
@@ -80,7 +80,12 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
             $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
         }
         if (!$this->_options['context']) {
-            $this->_options['context'] = get_context_instance(CONTEXT_SYSTEM);
+            // trying to set context to the current page context to make legacy files show in filepicker (e.g. forum post)
+            if (!empty($PAGE->context->id)) {
+                $this->_options['context'] = $PAGE->context;
+            } else {
+                $this->_options['context'] = context_system::instance();
+            }
         }
         $this->_options['trusted'] = trusttext_trusted($this->_options['context']);
         parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);