xref: /plugin/struct/types/AbstractBaseType.php (revision 083afc55c907a52e46afc662d6f808a98112c779)
1<?php
2namespace plugin\struct\types;
3
4use dokuwiki\Form\Form;
5
6abstract class AbstractBaseType {
7
8    /**
9     * @var array current config
10     */
11    protected $config = array();
12
13    /**
14     * @var string label for the field
15     */
16    protected $label = '';
17
18    /**
19     * @var bool is this a multivalue field?
20     */
21    protected $ismulti = false;
22
23    /** @var int sorting of fields */
24    protected $sort = 0;
25
26    /**
27     * AbstractBaseType constructor.
28     * @param int $sort This value is not stored with the type but adding it here, helps keeping things simple
29     * @param array|null $config The configuration, might be null if nothing saved, yet
30     * @param string $label The label for this field (empty for new definitions=
31     * @param bool $ismulti Should this field accept multiple values?
32     */
33    public function __construct($sort = 0, $config = null, $label = '', $ismulti = false) {
34        if(!is_null($config)) $this->config = array_merge($this->config, $config);
35        $this->label = $label;
36        $this->ismulti = (bool) $ismulti;
37        $this->sort = (int) $sort;
38    }
39
40    /**
41     * Return the current configuration for this type
42     *
43     * @return array
44     */
45    public function getConfig() {
46        return $this->config;
47    }
48
49    /**
50     * @return boolean
51     */
52    public function isMulti() {
53        return $this->ismulti;
54    }
55
56    /**
57     * @return int
58     */
59    public function getSort() {
60        return $this->sort;
61    }
62
63    /**
64     * @return string
65     */
66    public function getLabel() {
67        return $this->label;
68    }
69
70    /**
71     * Adds the admin schema editor to the given form
72     *
73     * @param Form $form
74     * @return void
75     */
76    abstract public function schemaEditor(Form $form);
77
78    /**
79     * Adds the frontend editor to the given form
80     *
81     * @param Form $form
82     * @return void
83     */
84    abstract public function frontendEditor(Form $form);
85
86    /**
87     * Output the stored data
88     *
89     * @param string|int $value the value stored in the database
90     * @return string the HTML to represent this data
91     */
92    abstract public function getDisplayData($value);
93}
94