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#

  • Number (number): a number.

  • Money (money): an amount in the currency’s minor units.

  • Currency (currency): an ISO 4217 code.

Dates#

  • Date (date): a calendar day.

  • DateTime (datetime): an instant.

  • DateRange (dateRange): a period kept in two date or two date-time properties.

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#

  • Json (json): a JSON object or array.

  • KeyValue (keyValue): a JSON object of text values, edited as rows.

  • Repeater (repeater): rows edited inside the form, in JSON or of a has-many.

  • Code (code): source text, edited in a code editor.

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#

  • File (file): an uploaded file’s storage key.

  • Image (image): an uploaded image’s storage key.

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

label(), help()

Its label, and a hint under the input.

placeholder('Such as KB-0042')

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, Textarea, Number, Money, Json, Code, Markdown, RichText, Currency, Tag, Select and Country (searchable or not), BelongsTo and ManyToMany (whose input otherwise says “Type to search”). Any other field refuses it with a LogicException when it is defined, so a placeholder never goes unseen. vector_describe carries it beside help.

required(), min(), max(), rule(Constraint::class, ...)

Validation, checked by the server and mirrored by the form. Any framework constraint may be used.

default()

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.

readonly()

Shown, never written.

sortable(), searchable(), filterable()

Allowed in the list grammar.

hideFromIndex(), hideFromShow(), hideFromForms(), onlyOn*()

Where the field appears.

summarize('sum'|'avg'|'min'|'max'|'count')

A totals row under the list.

inlineEditable()

Editable in its list cell; see Forms.

unique()

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 unique on every field.

component('name')

Rendered by a custom cell or input; see Customizing the UI.

props([...])

Extra settings passed to the UI.

meta('vendor.key', $value)

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

eq ne like nlike in nin

Number, money, id

eq ne lt lte gt gte between in nin

Boolean

eq

Date, datetime

eq ne lt lte gt gte between (a day against a timestamp spans the day)

Select, currency, belongs-to

eq ne in nin

Multiple select

any all (a bare value is any)

Flag group

any all over option keys (a bare value is any); in columns mode each flag also takes eq as group.key

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

{}

stdClass, ?stdClass

a JSON object

kept, at any depth the field allows

array|stdClass, array|stdClass|null

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.

  • Json reads 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 a stdClass property, which holds an object only. A CSV cell is the document’s JSON text.

  • KeyValue reads 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#