Fields#
A field maps one entity property to a column in lists, a value on the
record page and an input in forms. Text::make('sku', 'SKU') names the
property and, optionally, the label; without one the label is derived
from the name.
Catalog#
The descriptor names each field by its type, the identifier in brackets below. Each field class has a page of its own.
Text#
Id(id): the identifier.Text(string): a line of text.Textarea(text): long text, edited in a wide input.Email(email): an e-mail address.Url(url): an absolute http(s) URL, shown as a link.Password(password): a password, hashed before it is stored.Slug(slug): a URL-friendly name, derived from another field.Color(color): a colour.
How a password is hashed, and why an empty one keeps the stored hash, is on Password.
Numbers and money#
Dates#
Choices#
Boolean(boolean): true or false.Select(select): one or several of fixed options.BooleanGroup(booleanGroup): named on/off options edited as one group.Country(country): one or several ISO 3166-1 alpha-2 country codes.Tag(tag): free-text tags in a JSON list.
Structured data#
Rich text#
RichText(richtext): formatted content, stored as a structured document.Markdown(markdown): Markdown text for technical content.
Rendering a stored value on your own pages, HTML storage and how the admin shows rich text in the browser are on the RichText page; Markdown has a page of its own.
Files#
Uploads, serving and cleaning up are on Files and images.
Relations#
BelongsTo(belongsTo): one record of another resource.HasOne(hasOne): one related record of another resource.HasMany(hasMany): the related records of another resource.ManyToMany(manyToMany): any number of records of another resource.
Relations to another resource are made with
::to('name', TargetResource::class); titleField() overrides the
target’s title. A relation never crosses databases; a value pointing at
another database is an ordinary field. See Databases.
Computed fields#
Computed(computed): a read-only value a method of the resource computes from the record.
Common modifiers#
Every field takes:
Modifier |
Effect |
|---|---|
|
Its label, and a hint under the input. |
|
A hint inside the input’s empty text box, translated like the label. Only a field whose input has a text box takes one: text, e-mail, URL, slug, password and colour fields, |
|
Validation, checked by the server and mirrored by the form. Any framework constraint may be used. |
|
The value a new record starts with: the create form shows it pre-filled, and a create that leaves the field out takes it, validated like a value that was sent. Action dialogs and settings pages start from defaults too. |
|
Shown, never written. |
|
Allowed in the list grammar. |
|
Where the field appears. |
|
A totals row under the list. |
|
Editable in its list cell; see Forms. |
|
The value is unique (as its column’s index enforces; the ORM’s metadata does not carry indexes, so the field says so): a duplicated record starts without it, and an import can match rows by it. The descriptor publishes |
|
Rendered by a custom cell or input; see Customizing the UI. |
|
Extra settings passed to the UI. |
|
Metadata Vector publishes verbatim and never reads, for a package that builds on it; see Metadata for other packages. |
Conditions (visibleWhen(), requiredWhen(), disabledWhen()),
dependent choices and repeaters are on Forms.
Duplicating#
A record’s page offers Duplicate when the user may create and the
resource is replicable() (true unless it returns false): a create form
filled from the record. It copies every value the create form writes (a
many-to-many’s membership, a relationship repeater’s rows as new rows) except a
field marked unique(), which its column’s unique index would refuse,
and file or image keys, since a stored key belongs to its record. The
copy is saved through the ordinary create. The descriptor publishes
replicable on the resource.
Filter operators#
A filterable field offers the operators its value admits:
Value |
Operators |
|---|---|
Text |
|
Number, money, id |
|
Boolean |
|
Date, datetime |
|
Select, currency, belongs-to |
|
Multiple select |
|
Flag group |
|
A nullable column adds null and nnull. Collections are never
filterable. The list grammar and “any of” groups are on REST API.
Date bounds#
minDate() and maxDate() give a Date or DateTime field its earliest
and latest value, the bound itself included:
Date::make('joinedOn', 'Joined')->minDate('2010-01-01')->maxDate('today'),
DateTime::make('publishAt')->minDate('now'),
A bound is a Kinetis\Orm\Date (for a date) or a DateTimeInterface, a
string in the field’s own format (YYYY-MM-DD for a date, ISO 8601 with
its zone for a date-time, stored as its UTC instant), or a relative
keyword: today for a date, now for a date-time. A bound the field does
not take, and a minimum after the maximum, are refused when the field is
defined. min() and max() bound a text’s length, so a date field
refuses them with a LogicException that points to minDate() and
maxDate().
The server checks the bounds on every write: create, update, inline and
bulk edits, action inputs and imports. A value outside them is refused
with date_too_early (its min parameter naming the bound as declared,
today included) or date_too_late (max). A relative bound is
resolved each time a value is checked, never when the resource compiles,
so a worker that runs for days still compares with the current day.
now is the current instant. today is the current calendar day, which
depends on where one is: the server takes it as the current day anywhere
on Earth, so a minimum of today admits the earliest current day (that
of UTC-12) and a maximum the latest (that of UTC+14). The form resolves
today to the user’s own day in the browser’s time zone, which always
lies within, and uses it for the native control’s min and max and for
its own check. A date-time’s control edits local time and converts it to
the UTC instant the server compares.
The descriptor carries the bounds as the field’s DateBounds rule
(args: the kind, the minimum and the maximum, each null when not set),
and vector_describe lists it among the field’s rules.
JSON columns#
Json and KeyValue live in JSON columns. Declare the column JSON
on MySQL and MariaDB and jsonb on PostgreSQL, and the property as one
of these types, in any union order:
Property |
Holds |
|
|---|---|---|
|
a JSON object |
kept, at any depth the field allows |
|
a JSON object, or a JSON array as a list |
kept, at any depth the field allows |
Every JSON object is a stdClass and every JSON array a list, so {},
{"box": {}} and [] are stored and answered as sent. The build
refuses either field on any other property, naming the resource, the
property and these types. That includes an array or ?array
property: PHP holds {} and [] as the same array, so an empty object,
nested or not, would be stored as []. Declare such a property
array|stdClass (array|stdClass|null where it was ?array); the
column stays as it is. A resource with no fields of its own derives no
field for an array property.
Jsonreads as the stored document and writes a JSON object or array; a bare string, number or boolean is refused, and so is a list on astdClassproperty, which holds an object only. A CSV cell is the document’s JSON text.KeyValuereads and writes an object of text values.required()refuses an empty object,{}as much as[].
The create() and apply() hooks see the property’s own type: a
Json value is a stdClass tree (or a list, where the property allows
one) and a KeyValue value a stdClass of strings. A field’s own rules
check the value as sent, which holds a stdClass for every JSON object
of a REST body, of the values of the MCP vector_create and
vector_update tools, and of a value a revert puts back from the
audit.
An action’s or a settings group’s Json and KeyValue inputs have no
property and keep their objects the same way: a Json input is a
stdClass tree (or a list, where JSON sent one) and a KeyValue input
a stdClass of strings, whether the value came from a REST body, the
MCP vector_run_action tool or a queued run. An empty KeyValue input
that is not required is null.
Neither is sorted, filtered, searched, summarized or grouped.
How deep a value nests#
A database stores a JSON document only so deep, counted in nested
objects and arrays (the outermost is the first level): 100 levels on
MySQL, 31 on MariaDB before 12.2, and 2499 on MariaDB 12.2 and later
and on PostgreSQL, as the connection’s client reports it. A Json
field’s value, and a JSON repeater’s rows, are written to the record’s
column on the entity’s connection and to vector_audit on Vector’s own
connection, which wraps the value in two more levels ({field: {from, to}}). They are also answered: a JSON answer is encoded 512 levels
deep at most, and a record’s audit wraps a value in five. So a value
nests at most the least of:
the levels the record’s connection stores;
the levels Vector’s connection stores, less 2;
That is at most 98 levels wherever Vector’s tables are on MySQL (31
when the record’s connection is MariaDB before 12.2), at most 29
wherever they are on MariaDB before 12.2, and 507 when both connections
are PostgreSQL. A deeper value is a 422 on the field, too_deep,
with the limit as max, whether it came from a form, a bulk edit, an
inline edit, the MCP tools, a revert or an import; nothing is written. A row of a relationship
repeater is checked against its child resource’s own connection. A REST
body itself is read 63 levels deep at most, so a value sent through
REST nests at most 62 levels before this limit applies; the MCP tools
and an import carry deeper values to it.
Money and currencies#
Money is stored in minor units, following the currency’s ISO 4217
exponent: hundredths for most currencies, whole units for JPY,
thousandths for BHD. The schema publishes the exceptions to hundredths
as minorUnits, so the UI types and formats each amount correctly. The
input keeps what is typed and writes two decimals only when the field
is left.
The currency comes from one of three places:
currency('EUR'), fixed;currencyField('currency'), a field of the same record, serialized with every view that shows the money field;currencyField('order.currency'), a field of a related record reached through a belongs-to. That relation then carries the value as{id, label, currency}, and inside a relationship repeater a row reads the parent being edited.
A filter on a money field priced per record reads the typed amount in
hundredths. VECTOR_CURRENCY sets the starting code of a Currency
field that declares no default() (and allows the code).
See also#
Forms: conditions, dependent choices, repeaters, inline edits.
Files and images: uploads.
Authorization: hiding fields per user.