MDL-41611 mod_forum: Display inline available when supported
[moodle.git] / mod / folder / mod_form.php
CommitLineData
0e16b939 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Folder configuration form
20 *
9fe1fbcc
PS
21 * @package mod
22 * @subpackage folder
23 * @copyright 2009 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
0e16b939 25 */
26
9fe1fbcc 27defined('MOODLE_INTERNAL') || die();
bfebaf64 28
0e16b939 29require_once ($CFG->dirroot.'/course/moodleform_mod.php');
30
31class mod_folder_mod_form extends moodleform_mod {
32 function definition() {
33 global $CFG;
34 $mform = $this->_form;
35
36 $config = get_config('folder');
37
38 //-------------------------------------------------------
39 $mform->addElement('header', 'general', get_string('general', 'form'));
40 $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
41 if (!empty($CFG->formatstringstriptags)) {
42 $mform->setType('name', PARAM_TEXT);
43 } else {
b8ea3041 44 $mform->setType('name', PARAM_CLEANHTML);
0e16b939 45 }
46 $mform->addRule('name', null, 'required', null, 'client');
a74cd331 47 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
0e16b939 48 $this->add_intro_editor($config->requiremodintro);
49
50 //-------------------------------------------------------
51 $mform->addElement('header', 'content', get_string('contentheader', 'folder'));
67233725 52 $mform->addElement('filemanager', 'files', get_string('files'), null, array('subdirs'=>1, 'accepted_types'=>'*'));
38199c24
MG
53 $mform->addElement('select', 'display', get_string('display', 'mod_folder'),
54 array(FOLDER_DISPLAY_PAGE => get_string('displaypage', 'mod_folder'),
55 FOLDER_DISPLAY_INLINE => get_string('displayinline', 'mod_folder')));
56 $mform->addHelpButton('display', 'display', 'mod_folder');
98e9e915
FM
57 if (!$this->courseformat->has_view_page()) {
58 $mform->setConstant('display', FOLDER_DISPLAY_PAGE);
59 $mform->hardFreeze('display');
60 }
8763343a
RK
61 $mform->setExpanded('content');
62
f2957278 63 // Adding option to show sub-folders expanded or collapsed by default.
57e22804
RL
64 $mform->addElement('advcheckbox', 'showexpanded', get_string('showexpanded', 'folder'));
65 $mform->addHelpButton('showexpanded', 'showexpanded', 'mod_folder');
66 $mform->setDefault('showexpanded', $config->showexpanded);
0e16b939 67 //-------------------------------------------------------
68 $this->standard_coursemodule_elements();
69
70 //-------------------------------------------------------
71 $this->add_action_buttons();
72
73 //-------------------------------------------------------
74 $mform->addElement('hidden', 'revision');
75 $mform->setType('revision', PARAM_INT);
76 $mform->setDefault('revision', 1);
77 }
78
79 function data_preprocessing(&$default_values) {
80 if ($this->current->instance) {
81 // editing existing instance - copy existing files into draft area
82 $draftitemid = file_get_submitted_draft_itemid('files');
64f93798 83 file_prepare_draft_area($draftitemid, $this->context->id, 'mod_folder', 'content', 0, array('subdirs'=>true));
0e16b939 84 $default_values['files'] = $draftitemid;
85 }
86 }
38199c24
MG
87
88 function validation($data, $files) {
89 $errors = parent::validation($data, $files);
90
91 // Completion: Automatic on-view completion can not work together with
92 // "display inline" option
93 if (empty($errors['completion']) &&
94 array_key_exists('completion', $data) &&
95 $data['completion'] == COMPLETION_TRACKING_AUTOMATIC &&
96 !empty($data['completionview']) &&
97 $data['display'] == FOLDER_DISPLAY_INLINE) {
98 $errors['completion'] = get_string('noautocompletioninline', 'mod_folder');
99 }
100
101 return $errors;
102 }
0e16b939 103}