Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 80 lines (68 sloc) 3.333 kB
c82fa97 @adrianheine Add a bureaucracy field type for data aliases
adrianheine authored
1 <?php
2
3 if (file_exists(DOKU_PLUGIN . 'bureaucracy/fields/field.php')) {
4 require_once DOKU_PLUGIN . 'bureaucracy/fields/field.php';
5
6 class syntax_plugin_bureaucracy_field_dataplugin extends syntax_plugin_bureaucracy_field {
7
1bf2aa1 @adrianheine Use new bureaucracy field construct convention
adrianheine authored
8 function __construct($args) {
c82fa97 @adrianheine Add a bureaucracy field type for data aliases
adrianheine authored
9 $dthlp =& plugin_load('helper', 'data');
10 if(!$dthlp) msg('Loading the data helper failed. Make sure the data plugin is installed.',-1);
11
1bf2aa1 @adrianheine Use new bureaucracy field construct convention
adrianheine authored
12 $this->init($args);
c82fa97 @adrianheine Add a bureaucracy field type for data aliases
adrianheine authored
13 $n_args = array();
14 foreach ($args as $arg) {
15 if ($arg[0] !== '_') {
16 $n_args[] = $arg;
17 continue;
18 }
19 $datatype = $dthlp->_column($arg);
54591a3 @adrianheine Rewrite data alias handling
adrianheine authored
20 if (is_array($datatype['type'])) {
21 $datatype['basetype'] = $datatype['type']['type'];
22 $datatype['enum'] = $datatype['type']['enum'];
23 $datatype['type'] = $datatype['origtype'];
24 } else {
25 $datatype['basetype'] = $datatype['type'];
26 }
c82fa97 @adrianheine Add a bureaucracy field type for data aliases
adrianheine authored
27 }
28 $this->standardArgs($n_args);
29
30 if (isset($datatype['enum'])) {
31 $values = preg_split('/\s*,\s*/', $datatype['enum']);
32 if (!$datatype['multi'] && $this->opt['optional']) array_unshift($values, '');
e071b3b @adrianheine Use preset values for enum data bureaucracy fields
adrianheine authored
33 $this->opt['args'] = $values;
34 $this->additional = ($datatype['multi'] ? array('multiple' => 'multiple'): array());
c82fa97 @adrianheine Add a bureaucracy field type for data aliases
adrianheine authored
35 } else {
36 $classes = 'data_type_' . $datatype['type'] . ($datatype['multi'] ? 's' : '') . ' ' .
37 'data_type_' . $datatype['basetype'] . ($datatype['multi'] ? 's' : '');
38 $content = form_makeTextField('@@NAME@@', '@@VALUE@@', '@@LABEL@@', '', '@@CLASS@@ ' . $classes);
39
e071b3b @adrianheine Use preset values for enum data bureaucracy fields
adrianheine authored
40 $this->tpl = $content;
c82fa97 @adrianheine Add a bureaucracy field type for data aliases
adrianheine authored
41 }
42 }
43
e071b3b @adrianheine Use preset values for enum data bureaucracy fields
adrianheine authored
44 function render($params, $form) {
45 if (isset($this->tpl)) {
46 parent::render($params, $form);
47 } else {
bac2b5d @adrianheine Support multienums
adrianheine authored
48 // Is an enum type, otherwise $this->tpl would be set in __construct
e071b3b @adrianheine Use preset values for enum data bureaucracy fields
adrianheine authored
49 $this->_handlePreload();
50 if(!$form->_infieldset){
51 $form->startFieldset('');
52 }
53 if ($this->error) {
54 $params['class'] = 'bureaucracy_error';
55 }
56 $params = array_merge($this->opt, $params);
bac2b5d @adrianheine Support multienums
adrianheine authored
57 $params['value'] = preg_split('/\s*,\s*/', $params['value'], -1, PREG_SPLIT_NO_EMPTY);
58 if (count($params['value']) === 0) {
59 $params['value'] = $params['args'][0];
60 }
61
e071b3b @adrianheine Use preset values for enum data bureaucracy fields
adrianheine authored
62 $form->addElement(call_user_func_array('form_makeListboxField',
bac2b5d @adrianheine Support multienums
adrianheine authored
63 $this->_parse_tpl(array('@@NAME@@[]',
64 $params['args'], $params['value'],
e071b3b @adrianheine Use preset values for enum data bureaucracy fields
adrianheine authored
65 '@@LABEL@@', '', '@@CLASS@@', $this->additional),
66 $params)));
67 }
68 }
bac2b5d @adrianheine Support multienums
adrianheine authored
69
70 function handle_post($value) {
71 if (is_array($value)) {
72 $value = join(', ', $value);
73 }
74
75 return parent::handle_post($value);
76 }
77
c82fa97 @adrianheine Add a bureaucracy field type for data aliases
adrianheine authored
78 }
79 }
Something went wrong with that request. Please try again.