From 819e1ff0ad1346ee7a050b2252a9628a6ab76f08 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Mon, 11 Apr 2016 14:30:09 +0800 Subject: [PATCH] MDL-51267 mod_url: make the url and resource forms friendlier --- course/moodleform_mod.php | 7 +++++-- mod/resource/mod_form.php | 6 +----- mod/upgrade.txt | 2 ++ mod/url/mod_form.php | 6 +----- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index 841a2610b1d..3ff050d6147 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -777,9 +777,10 @@ abstract class moodleform_mod extends moodleform { * Add an editor for an activity's introduction field. * * @param null $customlabel Override default label for editor + * @param array $attributes add custom attributes for the editor, it sets rows size to 10 (default) to text editor. * @throws coding_exception */ - protected function standard_intro_elements($customlabel=null) { + protected function standard_intro_elements($customlabel=null, $attributes = array()) { global $CFG; $required = $CFG->requiremodintro; @@ -787,7 +788,9 @@ abstract class moodleform_mod extends moodleform { $mform = $this->_form; $label = is_null($customlabel) ? get_string('moduleintro') : $customlabel; - $mform->addElement('editor', 'introeditor', $label, array('rows' => 10), array('maxfiles' => EDITOR_UNLIMITED_FILES, + $attributes['rows'] = !empty($attributes['rows']) ? $attributes['rows'] : 10; + + $mform->addElement('editor', 'introeditor', $label, $attributes, array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $this->context, 'subdirs' => true)); $mform->setType('introeditor', PARAM_RAW); // no XSS prevention here, users must be trusted if ($required) { diff --git a/mod/resource/mod_form.php b/mod/resource/mod_form.php index 73c2ffdbda1..e79922e4c69 100644 --- a/mod/resource/mod_form.php +++ b/mod/resource/mod_form.php @@ -55,11 +55,7 @@ class mod_resource_mod_form extends moodleform_mod { } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); - $this->standard_intro_elements(); - - //------------------------------------------------------- - $mform->addElement('header', 'contentsection', get_string('contentheader', 'resource')); - $mform->setExpanded('contentsection'); + $this->standard_intro_elements(null, array('rows' => 5)); $filemanager_options = array(); $filemanager_options['accepted_types'] = '*'; diff --git a/mod/upgrade.txt b/mod/upgrade.txt index c8b4998da30..ecf5a477eee 100644 --- a/mod/upgrade.txt +++ b/mod/upgrade.txt @@ -3,6 +3,8 @@ information provided here is intended especially for developers. === 3.1 === +* A new parameter ($attributes) has been added to standard_intro_elements() on course/moodleform_mod.php. The + purpose of this parameter is allow developers to pass an array with custom attributes to the text editor. * Old /mod/MODULENAME/pix/icon.gif and enrol/paypal/pix/icon.gif GIF icons have been removed. Please use pix_icon renderable instead. diff --git a/mod/url/mod_form.php b/mod/url/mod_form.php index 7a50f472a30..db48a1db6f8 100644 --- a/mod/url/mod_form.php +++ b/mod/url/mod_form.php @@ -45,14 +45,10 @@ class mod_url_mod_form extends moodleform_mod { } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); - $this->standard_intro_elements(); - - //------------------------------------------------------- - $mform->addElement('header', 'content', get_string('contentheader', 'url')); $mform->addElement('url', 'externalurl', get_string('externalurl', 'url'), array('size'=>'60'), array('usefilepicker'=>true)); $mform->setType('externalurl', PARAM_RAW_TRIMMED); $mform->addRule('externalurl', null, 'required', null, 'client'); - $mform->setExpanded('content'); + $this->standard_intro_elements(null, array('rows' => 5)); //------------------------------------------------------- $mform->addElement('header', 'optionssection', get_string('appearance')); -- 2.43.0