This repository has been archived by the owner on Dec 28, 2024. It is now read-only.
forked from splitbrain/dokuwiki-plugin-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbureaucracy_field.php
64 lines (57 loc) · 2.8 KB
/
bureaucracy_field.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
<?php
if (file_exists(DOKU_PLUGIN . 'bureaucracy/fields/field.php')) {
require_once DOKU_PLUGIN . 'bureaucracy/fields/field.php';
class syntax_plugin_bureaucracy_field_dataplugin extends syntax_plugin_bureaucracy_field {
function __construct($syntax_plugin, $args) {
$dthlp =& plugin_load('helper', 'data');
if(!$dthlp) msg('Loading the data helper failed. Make sure the data plugin is installed.',-1);
$this->init($syntax_plugin, $args);
$n_args = array();
foreach ($args as $arg) {
if ($arg[0] !== '_') {
$n_args[] = $arg;
continue;
}
$datatype = $dthlp->_column($arg);
if (is_array($datatype['type'])) {
$datatype['basetype'] = $datatype['type']['type'];
$datatype['enum'] = $datatype['type']['enum'];
$datatype['type'] = $datatype['origtype'];
} else {
$datatype['basetype'] = $datatype['type'];
}
}
$this->standardArgs($n_args);
if (isset($datatype['enum'])) {
$values = preg_split('/\s*,\s*/', $datatype['enum']);
if (!$datatype['multi'] && $this->opt['optional']) array_unshift($values, '');
$this->opt['args'] = $values;
$this->additional = ($datatype['multi'] ? array('multiple' => 'multiple'): array());
} else {
$classes = 'data_type_' . $datatype['type'] . ($datatype['multi'] ? 's' : '') . ' ' .
'data_type_' . $datatype['basetype'] . ($datatype['multi'] ? 's' : '');
$content = form_makeTextField('@@NAME@@', '@@VALUE@@', '@@LABEL@@', '', '@@CLASS@@ ' . $classes);
$this->tpl = $content;
}
}
function render($params, $form) {
if (isset($this->tpl)) {
parent::render($params, $form);
} else {
$this->_handlePreload();
if(!$form->_infieldset){
$form->startFieldset('');
}
if ($this->error) {
$params['class'] = 'bureaucracy_error';
}
$params = array_merge($this->opt, $params);
$form->addElement(call_user_func_array('form_makeListboxField',
$this->_parse_tpl(array('@@NAME@@',
$params['args'], '@@VALUE|' . $params['args'][0] . '@@',
'@@LABEL@@', '', '@@CLASS@@', $this->additional),
$params)));
}
}
}
}