diff --git a/question/engine/lib.php b/question/engine/lib.php index 1889378e87d..b65ce4b9c24 100644 --- a/question/engine/lib.php +++ b/question/engine/lib.php @@ -954,6 +954,65 @@ abstract class question_utils { $text = str_replace('@@PLUGINFILE@@/', 'http://example.com/', $text); return html_to_text(format_text($text, $format, $options), 0, false); } + + /** + * Get the options required to configure the filepicker for one of the editor + * toolbar buttons. + * @param mixed $acceptedtypes array of types of '*'. + * @param int $draftitemid the draft area item id. + * @param object $context the context. + * @return object the required options. + */ + protected static function specific_filepicker_options($acceptedtypes, $draftitemid, $context) { + $filepickeroptions = new stdClass(); + $filepickeroptions->accepted_types = $acceptedtypes; + $filepickeroptions->return_types = FILE_INTERNAL | FILE_EXTERNAL; + $filepickeroptions->context = $context; + $filepickeroptions->env = 'filepicker'; + + $options = initialise_filepicker($filepickeroptions); + $options->context = $context; + $options->client_id = uniqid(); + $options->env = 'editor'; + $options->itemid = $draftitemid; + + return $options; + } + + /** + * Get filepicker options for question related text areas. + * @param object $context the context. + * @param int $draftitemid the draft area item id. + * @return array An array of options + */ + public static function get_filepicker_options($context, $draftitemid) { + return [ + 'image' => self::specific_filepicker_options(['image'], $draftitemid, $context), + 'media' => self::specific_filepicker_options(['video', 'audio'], $draftitemid, $context), + 'link' => self::specific_filepicker_options('*', $draftitemid, $context), + ]; + } + + /** + * Get editor options for question related text areas. + * @param object $context the context. + * @return array An array of options + */ + public static function get_editor_options($context) { + global $CFG; + + $editoroptions = [ + 'subdirs' => 0, + 'context' => $context, + 'maxfiles' => EDITOR_UNLIMITED_FILES, + 'maxbytes' => $CFG->maxbytes, + 'noclean' => 0, + 'trusttext' => 0, + 'autosave' => false + ]; + + return $editoroptions; + } } diff --git a/question/type/essay/renderer.php b/question/type/essay/renderer.php index a6352ef2580..99f4075f1df 100644 --- a/question/type/essay/renderer.php +++ b/question/type/essay/renderer.php @@ -358,28 +358,27 @@ class qtype_essay_format_editorfilepicker_renderer extends qtype_essay_format_ed $name, $context->id, $step->get_qt_var($name)); } + /** + * Get editor options for question response text area. + * @param object $context the context the attempt belongs to. + * @return array options for the editor. + */ protected function get_editor_options($context) { - // Disable the text-editor autosave because quiz has it's own auto save function. - return array( - 'subdirs' => 0, - 'maxbytes' => 0, - 'maxfiles' => -1, - 'context' => $context, - 'noclean' => 0, - 'trusttext'=> 0, - 'autosave' => false - ); + return question_utils::get_editor_options($context); } /** * Get the options required to configure the filepicker for one of the editor * toolbar buttons. + * @deprecated since 3.5 * @param mixed $acceptedtypes array of types of '*'. * @param int $draftitemid the draft area item id. * @param object $context the context. * @return object the required options. */ protected function specific_filepicker_options($acceptedtypes, $draftitemid, $context) { + debugging('specific_filepicker_options() is deprecated, use get_filepicker_options instead.', DEBUG_DEVELOPER); + $filepickeroptions = new stdClass(); $filepickeroptions->accepted_types = $acceptedtypes; $filepickeroptions->return_types = FILE_INTERNAL | FILE_EXTERNAL; @@ -395,17 +394,13 @@ class qtype_essay_format_editorfilepicker_renderer extends qtype_essay_format_ed return $options; } + /** + * @param object $context the context the attempt belongs to. + * @param int $draftitemid draft item id. + * @return array filepicker options for the editor. + */ protected function get_filepicker_options($context, $draftitemid) { - global $CFG; - - return array( - 'image' => $this->specific_filepicker_options(array('image'), - $draftitemid, $context), - 'media' => $this->specific_filepicker_options(array('video', 'audio'), - $draftitemid, $context), - 'link' => $this->specific_filepicker_options('*', - $draftitemid, $context), - ); + return question_utils::get_filepicker_options($context, $draftitemid); } protected function filepicker_html($inputname, $draftitemid) {