2 require_once ($CFG->dirroot
.'/course/moodleform_mod.php');
3 class editcategory_form
extends moodleform
{
6 function definition() {
8 $mform =& $this->_form
;
9 $category = $this->_customdata
;
11 // get list of categories to use as parents, with site as the first one
13 if (has_capability('moodle/category:manage', get_system_context()) ||
$category->parent
== 0) {
14 $options[0] = get_string('top');
18 // Editing an existing category.
19 make_categories_list($options, $parents, 'moodle/category:manage', $category->id
);
20 if (empty($options[$category->parent
])) {
21 $options[$category->parent
] = get_field('course_categories', 'name', 'id', $category->parent
);
23 $strsubmit = get_string('savechanges');
25 // Making a new category
26 make_categories_list($options, $parents, 'moodle/category:manage');
27 $strsubmit = get_string('createcategory');
30 $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
31 $mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
32 $mform->addRule('name', get_string('required'), 'required', null);
33 $mform->addElement('htmleditor', 'description', get_string('description'));
34 $mform->setType('description', PARAM_RAW
);
35 if (!empty($CFG->allowcategorythemes
)) {
37 $themes[''] = get_string('forceno');
38 $themes +
= get_list_of_themes();
39 $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
41 $mform->setHelpButton('description', array('writing', 'richtext'), false, 'editorhelpbutton');
43 $mform->addElement('hidden', 'id', 0);
44 $mform->setType('id', PARAM_INT
);
45 $mform->setDefault('id', $category->id
);
47 $this->add_action_buttons(true, $strsubmit);