objects

FieldType

How one kind of field encodes, decodes, validates and indexes a value.

Stateless and shared per class: the value, options and context come in as the FieldValue each method receives.

$fieldType Phlat\FieldType 12 methods
Show
  • absentIsValue Whether a field missing from a submitted form is itself the answer, like an unchecked checkbox, rather than "left as it was".
  • boundClass The class App::loadType() looks for when fieldtypes/{name}/{name}.php declares a bound subclass, e.g. "text" -> FieldTypeText.
  • child What `$field->{$key}` reads for a key the field has no property for: a container's sub-field, null for everything else.
  • decode Turns the stored value into what templates use.
  • empty Whether the field holds nothing: null, an empty string or an empty array.
  • encode Turns a submitted value into what is stored.
  • fromRequest Pulls this field's raw submitted value out of a request body - override when a type's editor posts something other than a flat string (see FieldTypeObject, whose sub-fields post as name="{$name}[{$key}]").
  • indexChildren Nested fields this field contributes to the index, as [subkey => FieldValue] - empty for a type that holds a value of its own.
  • indexValues Values this field contributes to the index, as [subkey => [string $value, ?float $numericValue]]. subkey '' for a plain scalar field, which becomes its column in the records table (the number when there is one, else the text), dotted/indexed subkeys for fieldtypes that flatten further, which become field_items rows.
  • preview One-line plain-text summary of the value for collapsed admin UI - empty string when there is nothing worth showing.
  • text What `{$field}` prints: the decoded value as a string.
  • validate Type-shape validation only (e.g. "is this a valid URL/email/number") - no knowledge of field config like required/min_length.

Methods

$fieldType->absentIsValue(): bool

Whether a field missing from a submitted form is itself the answer, like an unchecked checkbox, rather than "left as it was".

Returns bool

phlat/src/FieldType.php:53

boundClass

static
FieldType::boundClass(string $name): string

The class App::loadType() looks for when fieldtypes/{name}/{name}.php declares a bound subclass, e.g. "text" -> FieldTypeText.

Parameters (1)
$name string

Returns string

phlat/src/FieldType.php:19
$fieldType->child(FieldValue $field, string $key): mixed

What `$field->{$key}` reads for a key the field has no property for: a container's sub-field, null for everything else.

Parameters (2)
$field FieldValue
$key string

Returns mixed

phlat/src/FieldType.php:65
$fieldType->decode(FieldValue $field): mixed

Turns the stored value into what templates use.

Parameters (1)
$field FieldValue

Returns mixed

phlat/src/FieldType.php:35
$fieldType->empty(FieldValue $field): bool

Whether the field holds nothing: null, an empty string or an empty array.

Parameters (1)
$field FieldValue

Returns bool

phlat/src/FieldType.php:59
$fieldType->encode(FieldValue $field, mixed $raw): mixed

Turns a submitted value into what is stored.

Parameters (2)
$field FieldValue
$raw mixed

Returns mixed

phlat/src/FieldType.php:29
$fieldType->fromRequest(Request $request, string $name): mixed

Pulls this field's raw submitted value out of a request body - override when a type's editor posts something other than a flat string (see FieldTypeObject, whose sub-fields post as name="{$name}[{$key}]").

Parameters (2)
$request Request
$name string

Returns mixed

phlat/src/FieldType.php:47
$fieldType->indexChildren(FieldValue $field): array

Nested fields this field contributes to the index, as [subkey => FieldValue] - empty for a type that holds a value of its own.

Container types (stack, blocks, repeater) override it, and FieldIndex judges each child by its own type and search options.

Parameters (1)
$field FieldValue

Returns array

phlat/src/FieldType.php:85
$fieldType->indexValues(FieldValue $field): array

Values this field contributes to the index, as [subkey => [string $value, ?float $numericValue]]. subkey '' for a plain scalar field, which becomes its column in the records table (the number when there is one, else the text), dotted/indexed subkeys for fieldtypes that flatten further, which become field_items rows.

Parameters (1)
$field FieldValue

Returns array

phlat/src/FieldType.php:76
$fieldType->preview(FieldValue $field): string

One-line plain-text summary of the value for collapsed admin UI - empty string when there is nothing worth showing.

Parameters (1)
$field FieldValue

Returns string

phlat/src/FieldType.php:97
$fieldType->text(FieldValue $field): string

What `{$field}` prints: the decoded value as a string.

Parameters (1)
$field FieldValue

Returns string

phlat/src/FieldType.php:123
$fieldType->validate(FieldValue $field, mixed $raw): array

Type-shape validation only (e.g. "is this a valid URL/email/number") - no knowledge of field config like required/min_length.

Parameters (2)
$field FieldValue
$raw mixed

Returns array

phlat/src/FieldType.php:41