moodle/mod/resource/mod_form.php
fmarier 13ca1e06b8 mod/resource: MDL-18691 allow custom resource types to specify their name in their own lang directory
Before this change, the full name of the resource type had to be stored in the "resource" namespace (for example in /mod/resource/lang/en_utf8/resource.php).

Now it can be put in the "resource_foo" namespace:

e.g. in /mod/resource/type/foo/lang/en_utf8/resource_foo.php:

<?php
  $string['resourcetypefoo'] = 'Link to a Foo Bar document';
?>
2009-03-27 03:21:10 +00:00

61 lines
2.3 KiB
PHP

<?php
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
class mod_resource_mod_form extends moodleform_mod {
var $_resinstance;
function definition() {
global $CFG, $DB;
$mform =& $this->_form;
// this hack is needed for different settings of each subtype
if (!empty($this->_instance)) {
if($res = $DB->get_record('resource', array('id'=>$this->_instance))) {
$type = $res->type;
} else {
print_error('invalidassignment', 'resource');
}
} else {
$type = required_param('type', PARAM_ALPHA);
}
$mform->addElement('hidden', 'type', $type);
$mform->setDefault('type', $type);
require($CFG->dirroot.'/mod/resource/type/'.$type.'/resource.class.php');
$resclass = 'resource_'.$type;
$this->_resinstance = new $resclass();
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
// $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment'));
$mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEAN);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addElement('htmleditor', 'summary', get_string('summary'));
$mform->setType('summary', PARAM_RAW);
$mform->setHelpButton('summary', array('summary', get_string('summary'), 'resource'));
// summary should be optional again MDL-9485
//$mform->addRule('summary', get_string('required'), 'required', null, 'client');
$mform->addElement('header', 'typedesc', resource_get_name($type));
$this->_resinstance->setup_elements($mform);
$this->standard_coursemodule_elements(array('groups'=>false, 'groupmembersonly'=>true, 'gradecat'=>false));
$this->add_action_buttons();
}
function data_preprocessing(&$default_values){
$this->_resinstance->setup_preprocessing($default_values);
}
}
?>