Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / form / builder / field / IFormField.class.php
CommitLineData
3969e409 1<?php
a9229942 2
3969e409 3namespace wcf\system\form\builder\field;
a9229942 4
3969e409
MS
5use wcf\data\IStorableObject;
6use wcf\system\form\builder\field\validation\IFormFieldValidationError;
7use wcf\system\form\builder\field\validation\IFormFieldValidator;
8use wcf\system\form\builder\IFormChildNode;
9use wcf\system\form\builder\IFormElement;
10
11/**
12 * Represents an actual form field storing a value.
a9229942
TD
13 *
14 * @author Matthias Schmidt
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\System\Form\Builder\Field
18 * @since 5.2
3969e409 19 */
a9229942
TD
20interface IFormField extends IFormChildNode, IFormElement
21{
22 /**
23 * Adds the given validation error to this field and returns this field.
24 *
25 * @param IFormFieldValidationError $error validation error
26 * @return static this field
27 */
28 public function addValidationError(IFormFieldValidationError $error);
29
30 /**
31 * Adds the given validation error to this field and returns this field.
32 *
33 * @param IFormFieldValidator $validator
34 * @return static this field
35 */
36 public function addValidator(IFormFieldValidator $validator);
37
38 /**
39 * Returns the html representation of the form field only without any of the surrounding
40 * structural html elements.
41 *
42 * @return string html representation of node
43 */
44 public function getFieldHtml();
45
46 /**
47 * Returns the name of the JavaScript data handler module for this form field or `null` if
48 * there is no such module.
49 *
50 * @return null|string
51 */
52 public function getJavaScriptDataHandlerModule();
53
54 /**
55 * Returns the name of the object property this field represents.
56 *
57 * If no object property has been explicitly set, the field's id is returned.
58 *
59 * @return string
60 */
61 public function getObjectProperty();
62
63 /**
64 * Returns the field value saved in the database.
65 *
66 * This method is useful if the actual returned by `getValue()`
67 * cannot be stored in the database as-is. If the return value of
68 * `getValue()` is, however, the actual value that should be stored
69 * in the database, this method is expected to call `getValue()`
70 * internally.
71 *
72 * @return mixed
73 */
74 public function getSaveValue();
75
76 /**
77 * Returns the validation errors of this field.
78 *
79 * @return IFormFieldValidationError[] field validation errors
80 */
81 public function getValidationErrors();
82
83 /**
84 * Returns all field value validators of this field.
85 *
86 * @return IFormFieldValidator[] field value validators of this field
87 */
88 public function getValidators();
89
90 /**
91 * Returns the value of this field or `null` if no value has been set.
92 *
93 * @return mixed
94 */
95 public function getValue();
96
97 /**
98 * Returns `true` if this field has a validator with the given id and
99 * returns `false` otherwise.
100 *
101 * @param string $validatorId id of the checked validator
102 * @return bool
103 *
104 * @throws \InvalidArgumentException if the given id is invalid
105 */
106 public function hasValidator($validatorId);
107
108 /**
109 * Returns `true` if this field provides a value that can simply be stored
110 * in a column of the database object's database table and returns `false`
111 * otherwise.
112 *
113 * Note: If `false` is returned, this field should probably add its own
114 * `IFormFieldDataProcessor` object to the form document's data processor.
115 * A suitable place to add the processor is the `parent()`
116 *
117 * @return bool
118 */
119 public function hasSaveValue();
120
121 /**
122 * Returns `true` if this field has to be filled out and returns `false` otherwise.
123 * By default, fields do not have to be filled out.
124 *
125 * @return bool
126 */
127 public function isRequired();
128
129 /**
130 * Informs the form field of the updated object (and loads the field value from the given data)
131 * and returns this field.
132 *
133 * It is important to extract the value from the `$data` array instead of getting it directly
134 * from the object as the entries of `$data` have been processed by the data processors.
135 *
136 * @param array $data object data
137 * @param IStorableObject $object updated object
138 * @param bool $loadValues indicates if object data is loaded
139 * @return static this field
140 */
141 public function updatedObject(array $data, IStorableObject $object, $loadValues = true);
142
143 /**
144 * Sets the name of the object property this field represents. If an empty
145 * is passed, the object property is unset.
146 *
147 * The object property allows having different fields (requiring different ids)
148 * that represent the same object property which is handy when available options
149 * of the field's value depend on another field. Having object property allows
150 * to define different fields for each value of the other field and to use form
151 * field dependencies to only show the appropriate field.
152 *
153 * @param string $objectProperty object property this field represents
154 * @return IFormField
155 *
156 * @throws \InvalidArgumentException if the passed object property is no valid id
157 */
158 public function objectProperty($objectProperty);
159
160 /**
161 * Reads the value of this field from request data and return this field.
162 *
163 * @return static this field
164 */
165 public function readValue();
166
167 /**
168 * Removes the field value validator with the given id and returns this field.
169 *
170 * @param string $validatorId id of the removed validator
171 * @return static this field
172 *
173 * @throws \InvalidArgumentException if the given id is invalid or no such validator exists
174 */
175 public function removeValidator($validatorId);
176
177 /**
178 * Sets whether it is required to fill out this field and returns this field.
179 *
180 * @param bool $required determines if field has to be filled out
181 * @return static this field
182 */
183 public function required($required = true);
184
185 /**
186 * Sets the value of this field and returns this field.
187 *
188 * @param mixed $value new field value
189 * @return static this field
190 *
191 * @throws \InvalidArgumentException if the given value is of an invalid type or otherwise is invalid
192 */
193 public function value($value);
3969e409 194}