MDL-56532 tool_usertours: Improve help for step editing
[moodle.git] / admin / tool / usertours / classes / local / forms / editstep.php
CommitLineData
001fc061
AN
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Form for editing steps.
19 *
20 * @package tool_usertours
21 * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25namespace tool_usertours\local\forms;
26
27defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
28
29require_once($CFG->libdir . '/formslib.php');
30
31/**
32 * Form for editing steps.
33 *
34 * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37class editstep extends \moodleform {
38 /**
39 * @var tool_usertours\step $step
40 */
41 protected $step;
42
43 /**
44 * Create the edit step form.
45 *
46 * @param string $target The target of the form.
47 * @param step $step The step being editted.
48 */
49 public function __construct($target, \tool_usertours\step $step) {
50 $this->step = $step;
51
52 parent::__construct($target);
53 }
54
55 /**
56 * Form definition.
57 */
58 public function definition() {
59 $mform = $this->_form;
60
c6698a4f 61 $mform->addElement('header', 'heading_target', get_string('target_heading', 'tool_usertours'));
001fc061
AN
62 $types = [];
63 foreach (\tool_usertours\target::get_target_types() as $value => $type) {
64 $types[$value] = get_string('target_' . $type, 'tool_usertours');
65 }
66 $mform->addElement('select', 'targettype', get_string('targettype', 'tool_usertours'), $types);
c6698a4f 67 $mform->addHelpButton('targettype', 'targettype', 'tool_usertours');
001fc061
AN
68
69 // The target configuration.
70 foreach (\tool_usertours\target::get_target_types() as $value => $type) {
71 $targetclass = \tool_usertours\target::get_classname($type);
72 $targetclass::add_config_to_form($mform);
73 }
74
c6698a4f
AN
75 // Content of the step.
76 $mform->addElement('header', 'heading_content', get_string('content_heading', 'tool_usertours'));
001fc061
AN
77 $mform->addElement('textarea', 'title', get_string('title', 'tool_usertours'));
78 $mform->addRule('title', get_string('required'), 'required', null, 'client');
79 $mform->setType('title', PARAM_TEXT);
80 $mform->addHelpButton('title', 'title', 'tool_usertours');
81
82 $mform->addElement('textarea', 'content', get_string('content', 'tool_usertours'));
83 $mform->addRule('content', get_string('required'), 'required', null, 'client');
84 $mform->setType('content', PARAM_RAW);
85 $mform->addHelpButton('content', 'content', 'tool_usertours');
86
87 // Add the step configuration.
c6698a4f 88 $mform->addElement('header', 'heading_options', get_string('options_heading', 'tool_usertours'));
001fc061
AN
89 // All step configuration is defined in the step.
90 $this->step->add_config_to_form($mform);
91
92 // And apply any form constraints.
93 foreach (\tool_usertours\target::get_target_types() as $value => $type) {
94 $targetclass = \tool_usertours\target::get_classname($type);
95 $targetclass::add_disabled_constraints_to_form($mform);
96 }
97
98 $this->add_action_buttons();
99 }
100}