Description API
The Description API is how a model tells the user interface what to show. The model returns plain description objects; they are serialized to JSON and the React components (Table, Form, inputs) render themselves from them. You change the UI by changing the description, usually without any React code.
| Description | Created by | Class | Page |
|---|---|---|---|
| Table (title, filters, buttons, permissions, columns) | Model::describeTable() |
Hubleto\Framework\Description\Table |
Table |
| Form (title, buttons, defaults, relations) | Model::describeForm() |
Hubleto\Framework\Description\Form |
Form |
| Input (type, title, hint, enum values, component) | Column objects, describeInput() |
Hubleto\Framework\Description\Input |
below |
Descriptions.
Flow
React Table ──GET api/table/describe?model=...──► Model::describeTable() ──► Description\Table (JSON)
React Form ──GET api/form/describe?model=...──► Model::describeForm() ──► Description\Form (JSON)
Model::describeColumns() ──► Input descriptions
Input: the properties of a column
Every column is a Description\Input. These properties can be set with fluent setters:
| Property | Setter | Meaning |
|---|---|---|
| type | setType() |
The type of the input (set by the column class). |
| title | setTitle() |
Label. |
| required, readonly | setRequired(), setReadonly() |
Validation and editability. |
| defaultValue | setDefaultValue() |
Value of a new record. |
| hint, examples | setHint(), setExamples() |
Help texts. |
| unit, icon, format, decimals, step | setUnit(), setIcon(), ... |
Number and amount formatting. |
| enumValues, enumCssClasses | setEnumValues(), setEnumCssClasses() |
Fixed lists of values and their colors. |
| predefinedValues | setPredefinedValues() |
Suggested values of a text input. |
| lookupModel, endpoint, creatable | setLookupModel(), setEndpoint(), setCreatable() |
Dropdown for Lookup columns. |
| reactComponent | setReactComponent() |
Which input component renders it. |
| cssClass | setCssClass() |
CSS classes of the input. |
| yesText, noText | setYesText(), setNoText() |
Labels of a Boolean input. |
| properties | setProperty($name, $value) |
Any other property, e.g. sql of a virtual column. |
Properties of Description\Input.
NOTE
setPlaceholder()andsetFormat()are declared with aboolparameter in the current framework although the properties are strings. Check that the placeholder you set really appears in the form. If it does not, describe the problem inhubleto-framework-patches.md.
Customize an input of one model
describeInput($columnName) returns the input description of a column. Override it to change it for this model only:
apps/Customers/Models/Customer.php (excerpt)
public function describeInput(string $columnName): Input
{
$description = parent::describeInput($columnName);
switch ($columnName) {
case 'shared_folder':
$description
->setReactComponent('InputHyperlink')
->setHint($this->translate('Link to shared folder (online storage) with related documents'))
;
break;
}
return $description;
}
More in describeInput().
