Fieldtype class
Fieldtype is a module type used to represent a type of field. All Fieldtype modules descend from this.
Almost all methods in a Fieldtype are primarily of concern to module developers, as Fieldtype modules do not
have a public API (most of the time). Instead, they provide methods used by Page
and Field
objects (and related)
to work with the field data. Most Fieldtype modules only need to implement a few methods like
Fieldtype::sanitizeValue()
(which is required) and Fieldtype::getDatabaseSchema()
, as the default implementation
of most other methods provided in this Fieldtype class accounts for most situations already.
There are 25 Fieldtype types in the core, plus many more Fieldtype modules in our directory.
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Fieldtype
class also inherits all the methods and properties of: WireData and Wire.
Loading
Saving
Name | Return | Summary | |
---|---|---|---|
Fieldtype::replacePageField() Fieldtype::replacePageField(Page $src, Page $dst, Field $field) Fieldtype::replacePageField(Page $src, Page $dst, Field $field) | bool | Move this field’s data from one page to another. | |
Fieldtype::savePageField() Fieldtype::savePageField(Page $page, Field $field) Fieldtype::savePageField(Page $page, Field $field) | bool | Save the given field from given page to the database. | |
Fieldtype::sleepValue() Fieldtype::sleepValue(Page $page, Field $field, $value) Fieldtype::sleepValue(Page $page, Field $field, $value) | string int float array | Given an 'awake' value, as set by wakeupValue(), convert the value back to a basic type for storage in database. |
Finding
Name | Return | Summary | |
---|---|---|---|
Fieldtype::getMatchQuery() Fieldtype::getMatchQuery(PageFinderDatabaseQuerySelect $query, string $table, string $subfield, string $operator, mixed $value) Fieldtype::getMatchQuery(PageFinderDatabaseQuerySelect $query, string $table, string $subfield, string $operator, mixed $value) | PageFinderDatabaseQuerySelect DatabaseQuerySelect | Get the database query that matches a Fieldtype table’s data with a given value. | |
Fieldtype::getSelectorInfo() Fieldtype::getSelectorInfo(Field $field) Fieldtype::getSelectorInfo(Field $field, array $data = []) | array | Return array with information about what properties and operators can be used with this field. | |
Fieldtype::isEmptyValue() Fieldtype::isEmptyValue(Field $field, mixed $value) Fieldtype::isEmptyValue(Field $field, mixed $value) | bool | Return whether the given value is considered empty or not. |
Formatting
Name | Return | Summary | |
---|---|---|---|
Fieldtype::exportValue() Fieldtype::exportValue(Page $page, Field $field, $value) Fieldtype::exportValue(Page $page, Field $field, $value, array $options = []) | string float int array | Given a value, return an portable version of it as either a string, int, float or array | |
Fieldtype::formatValue() Fieldtype::formatValue(Page $page, Field $field, $value) Fieldtype::formatValue(Page $page, Field $field, $value) | mixed | Format the given value for output and return a string of the formatted value | |
Fieldtype::markupValue() Fieldtype::markupValue(Page $page, Field $field) Fieldtype::markupValue(Page $page, Field $field, mixed $value = null, string $property = '') | string MarkupFieldtype | Render a markup string of the value. |
Configuration
Creating
Name | Return | Summary | |
---|---|---|---|
Fieldtype::createField() Fieldtype::createField(Field $field) Fieldtype::createField(Field $field) | bool | Create a new field table in the database. | |
Fieldtype::getDatabaseSchema() Fieldtype::getDatabaseSchema(Field $field) Fieldtype::getDatabaseSchema(Field $field) | array | Get the database schema for this field |
Deleting
Name | Return | Summary | |
---|---|---|---|
Fieldtype::deleteField() Fieldtype::deleteField(Field $field) Fieldtype::deleteField(Field $field) | bool | Delete the given field, which implies: drop the table used by the field. | |
Fieldtype::deletePageField() Fieldtype::deletePageField(Page $page, Field $field) Fieldtype::deletePageField(Page $page, Field $field) | bool | Delete the given Field from the given Page. | |
Fieldtype::deleteTemplateField() Fieldtype::deleteTemplateField(Template $template, Field $field) Fieldtype::deleteTemplateField(Template $template, Field $field) | bool | Delete the given Field from all pages using the given template, without loading those pages. | |
Fieldtype::emptyPageField() Fieldtype::emptyPageField(Page $page, Field $field) Fieldtype::emptyPageField(Page $page, Field $field) | bool | Empty out the DB table data for page field, but leave everything else in tact. |
Other
Name | Return | Summary | |
---|---|---|---|
Fieldtype::cloneField() Fieldtype::cloneField(Field $field) Fieldtype::cloneField(Field $field) | Field | Return a cloned copy of $field | |
Fieldtype::get() Fieldtype::get(string $key) Fieldtype::get(string $key) | mixed | Get a property from this Fieldtype’s data | |
Fieldtype::getInputfield() Fieldtype::getInputfield(Page $page, Field $field) Fieldtype::getInputfield(Page $page, Field $field) | Inputfield null | Return new instance of the Inputfield module associated with this Fieldtype. | |
Fieldtype::install() Fieldtype::install() Fieldtype::install() | None | Install this Fieldtype, consistent with optional Module interface | |
Fieldtype::longName | string | Long name of Fieldtype, which is typically the module title. | |
Fieldtype::name | string | Name of Fieldtype module. | |
Fieldtype::shortName | string | Short name of Fieldtype, which excludes the "Fieldtype" prefix. | |
Fieldtype::uninstall() Fieldtype::uninstall() Fieldtype::uninstall() | None | Uninstall this Fieldtype, consistent with optional Module interface | |
Fieldtype::upgrade() Fieldtype::upgrade($fromVersion, $toVersion) Fieldtype::upgrade($fromVersion, $toVersion) | None | Called when module version changes |
Common
Name | Return | Summary | |
---|---|---|---|
Fieldtype::getFieldClass() Fieldtype::getFieldClass() Fieldtype::getFieldClass(array $a = []) | string | Get class name to use Field objects of this type (must be class that extends Field class) | |
Fieldtype::importValue() Fieldtype::importValue(Page $page, Field $field, $value) Fieldtype::importValue(Page $page, Field $field, $value, array $options = []) | string int array object | Given a value originally generated by exportValue() convert it to a live/runtime value. | |
Fieldtype::isDeleteValue() Fieldtype::isDeleteValue(Page $page, Field $field, mixed $value) Fieldtype::isDeleteValue(Page $page, Field $field, mixed $value) | bool | Is given value one that should cause the DB row(s) to be deleted rather than saved? | |
Fieldtype::ready() Fieldtype::ready() Fieldtype::ready() | None |
For hooks
These methods are only useful for hooking and should not be called directly.
Name | Return | Summary | |
---|---|---|---|
Fieldtype::getFieldSetups() Fieldtype::getFieldSetups() Fieldtype::getFieldSetups() | array | Get predefined setups for newly created fields of this type | |
Fieldtype::renamedField() Fieldtype::renamedField(Field $field, string $prevName) Fieldtype::renamedField(Field $field, string $prevName) | None | Hook called by Fields::save() after a field using this type has been renamed | |
Fieldtype::saveFieldReady() Fieldtype::saveFieldReady(Field $field) Fieldtype::saveFieldReady(Field $field) | None | Hook called by Fields::save() when a field is about to be saved | |
Fieldtype::savedField() Fieldtype::savedField(Field $field) Fieldtype::savedField(Field $field) | None | Called when Field using this Fieldtype has been saved |
Additional methods and properties
In addition to the methods and properties above, Fieldtype also inherits the methods and properties of these classes:
Core Fieldtype types
Type | Summary |
---|---|
FieldtypeCheckbox | This Fieldtype stores an ON/OFF toggle via a single checkbox. The ON value is 1 and OFF value is 0. |
FieldtypeComments | Field that stores user posted comments for a single Page |
FieldtypeDatetime | Field that stores a date and optionally time |
FieldtypeEmail | Field that stores an e-mail address |
FieldtypeFieldsetClose | Close a fieldset opened by FieldsetOpen. |
FieldtypeFieldsetOpen | Open a fieldset to group fields. Should be followed by a Fieldset (Close) after one or more fields. |
FieldtypeFieldsetTabOpen | Open a fieldset to group fields. Same as Fieldset (Open) except that it displays in a tab instead. |
FieldtypeFile | Field that stores one or more files |
FieldtypeFloat | Field that stores a floating point number |
FieldtypeImage | Field that stores one or more GIF, JPG, or PNG images |
FieldtypeInteger | Field that stores an integer |
FieldtypeModule | Field that stores a reference to another module |
FieldtypeOptions | Field that stores single and multi select options. |
FieldtypePage | Field that stores one or more references to ProcessWire pages |
FieldtypePageTitle | Field that stores a page title |
FieldtypePassword | Field that stores a hashed and salted password |
FieldtypeRepeater | Maintains a collection of fields that are repeated for any number of times. |
FieldtypeText | Field that stores a single line of text |
FieldtypeTextarea | Field that stores multiple lines of text |
FieldtypeToggle | Configurable yes/no, on/off toggle alternative to a checkbox, plus optional “other” option. |
FieldtypeURL | Field that stores a URL |
API reference based on ProcessWire core version 3.0.251