1<?php
2/**
3 * Class helper_plugin_bureaucracyau_fieldselect
4 *
5 * Creates a dropdown list
6 */
7class helper_plugin_bureaucracyau_fieldselect extends helper_plugin_bureaucracyau_field {
8
9    protected $mandatory_args = 3;
10
11    /**
12     * Arguments:
13     *  - cmd
14     *  - label
15     *  - option1|option2|etc
16     *  - ^ (optional)
17     *
18     * @param array $args The tokenized definition, only split at spaces
19     */
20    public function initialize($args) {
21        $this->init($args);
22        $this->opt['args'] = array_map('trim', explode('|',array_shift($args)));
23        $this->standardArgs($args);
24        if (!isset($this->opt['value']) && isset($this->opt['optional'])) {
25            array_unshift($this->opt['args'],' ');
26        }
27    }
28
29    /**
30     * Render the field as XHTML
31     *
32     * Outputs the represented field using the passed Doku_Form object.
33     * Additional parameters (CSS class & HTML name) are passed in $params.
34     *
35     * @params array     $params Additional HTML specific parameters
36     * @params Doku_Form $form   The target Doku_Form object
37     * @params int       $formid unique identifier of the form which contains this field
38     */
39    public function renderfield($params, Doku_Form $form, $formid) {
40        $this->_handlePreload();
41        if(!$form->_infieldset){
42            $form->startFieldset('');
43        }
44        if ($this->error) {
45            $params['class'] = 'bureaucracyau_error';
46        }
47        $params = array_merge($this->opt, $params);
48        $form->addElement(call_user_func_array('form_makeListboxField',
49                                                $this->_parse_tpl(
50                                                    array(
51                                                        '@@NAME@@',
52                                                        $params['args'],
53                                                        '@@VALUE|' . $params['args'][0] . '@@',
54                                                        '@@DISPLAY@@',
55                                                        '@@ID@@',
56                                                        '@@CLASS@@'
57                                                    ),
58                                                    $params
59                                                )));
60    }
61}
62