forked from brickfield/moodle-block_accessibility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_form.php
94 lines (71 loc) · 3.35 KB
/
edit_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
// This settings will be available throughout the block.
// Usage example: $this->config->autosave
class block_accessibility_edit_form extends block_edit_form {
CONST CNF_AUTOSAVE = 'config_autosave';
CONST CNF_ATBAR = 'config_showATbar';
CONST CNF_FG = 'config_fg'; // fg1, fg2,...
CONST CNF_BG = 'config_bg'; // bg1, bg2,...
CONST RE_COLOUR = '/^#[a-f0-9]{6}$/i';
protected function specific_definition($mform) {
// load default colours
global $CFG;
require_once($CFG->dirroot.'/blocks/accessibility/defaults.php');
/* not implemented, so far I'm not sure if it's going to be useful
// auto-save user settings
$mform->addElement('advcheckbox',self::CNF_AUTOSAVE,
get_string (self::CNF_AUTOSAVE, 'block_accessibility'),
get_string (self::CNF_AUTOSAVE.'_checkbox', 'block_accessibility' ),
null,
array (0, 1)
);
$mform->setDefault(self::CNF_AUTOSAVE, 0);
$mform->setType (self::CNF_AUTOSAVE, PARAM_INT);
$mform->addHelpButton(self::CNF_AUTOSAVE, self::CNF_AUTOSAVE, 'block_accessibility');
*/
// allow ATbar
$mform->addElement('advcheckbox', self::CNF_ATBAR,
get_string (self::CNF_ATBAR, 'block_accessibility'),
get_string (self::CNF_ATBAR.'_checkbox', 'block_accessibility'),
null,
array (0, 1)
);
$mform->setDefault(self::CNF_ATBAR, 1);
$mform->setType (self::CNF_ATBAR, PARAM_INT);
$mform->addHelpButton(self::CNF_ATBAR, self::CNF_ATBAR, 'block_accessibility');
// An idea: put here default font-size setting?
// colour schemes
for($i=2; $i<5; $i++) { // this is how many declarations we defined in defaults.php
// get previously saved configuration
$form = $this->block->config; // or cast it to (array) and get properties like with []
$fg = str_replace('config_', '', self::CNF_FG);
$bg = str_replace('config_', '', self::CNF_BG);
$fg_colour = isset($form->{$fg.$i})? $form->{$fg.$i} : $defaults['fg'.$i];
$bg_colour = isset($form->{$bg.$i})? $form->{$bg.$i} : $defaults['bg'.$i];
// display scheme example and identifier number of a scheme
$mform->addElement('html', '
<div class="fitem" style="padding:10px 0 8px">
<div class="fitemtitle"></div>
<div class="felement">
<span style="padding:2px 8px; color:'.$fg_colour.'; border:1px solid '.$fg_colour.'; background:'.$bg_colour.' !important">A</span>
Colour scheme #'.$i.'
</div>
</div>');
// foreground colour
$id = self::CNF_FG.$i;
$mform->addElement('text', $id, get_string(self::CNF_FG, 'block_accessibility'));
$mform->setDefault($id, $defaults['fg'.$i]);
$mform->setType($id, PARAM_TEXT);
$mform->addHelpButton($id, self::CNF_FG, 'block_accessibility');
$mform->addRule($id, get_string('color_input_error', 'block_accessibility'), 'regex', self::RE_COLOUR, 'server', false, false);
// background colour
$id = self::CNF_BG.$i;
$mform->addElement('text', $id, get_string(self::CNF_BG, 'block_accessibility'));
$mform->setDefault($id, $defaults['bg'.$i]);
$mform->setType($id, PARAM_TEXT);
$mform->addHelpButton($id, self::CNF_BG, 'block_accessibility');
$mform->addRule($id, get_string('color_input_error', 'block_accessibility'), 'regex', self::RE_COLOUR, 'server', false, false);
}
// if someone is willing to do settings form reset button, it would be helpful
}
}