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.


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 / Finding / Formatting / Configuration / Creating / Deleting / Other / Common

Loading

Name Return Summary  
Fieldtype::getBlankValue($page, Field $field) string, int, object or null Return the blank value for this fieldtype, whether that is a blank string, zero value, blank object or array
Fieldtype::getLoadQuery(Field $field, DatabaseQuerySelect $query) DatabaseQuerySelect Return the query used for loading all parts of the data from this field.
Fieldtype::getLoadQueryAutojoin(Field $field, DatabaseQuerySelect $query) DatabaseQuerySelect or null Return the query used for Autojoining this field (if different from getLoadQuery) or NULL if autojoin not allowed.
Fieldtype::loadPageField(Page $page, Field $field) mixed or null Load the given page field from the database table and return the value.
Fieldtype::loadPageFieldFilter(Page $page, Field $field, $selector) mixed or null Load the given page field from the database table and return a *filtered* value.
Fieldtype::sanitizeValue(Page $page, Field $field, $value) string, int, WireArray or object Sanitize the value for runtime storage and return it.
Fieldtype::wakeupValue(Page $page, Field $field, $value) string, int, array or object Given a raw value (value as stored in database), return the value as it would appear in a Page object.

Saving

Name Return Summary  
Fieldtype::replacePageField(Page $src, Page $dst, Field $field) bool Move this field’s data from one page to another.
Fieldtype::savePageField(Page $page, Field $field) bool Save the given field from given page to the database.
Fieldtype::sleepValue(Page $page, Field $field, $value) string, int, float or 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(DatabaseQuerySelect $query, string $table, string $subfield, string $operator, mixed $value) DatabaseQuery Get the database query that matches a Fieldtype table’s data with a given value.
Fieldtype::getSelectorInfo(Field $field) array Return array with information about what properties and operators can be used with this field.
Fieldtype::isEmptyValue(Field $field, mixed $value) bool Return whether the given value is considered empty or not.

Formatting

Name Return Summary  
Fieldtype::exportValue(Page $page, Field $field, $value) string, float, int or array Given a value, return an portable version of it as either a string, int, float or array
Fieldtype::formatValue(Page $page, Field $field, $value) mixed Format the given value for output and return a string of the formatted value
Fieldtype::markupValue(Page $page, Field $field) string or MarkupFieldtype Render a markup string of the value.

Configuration

Name Return Summary  
Fieldtype::exportConfigData(Field $field, array $data) array Export configuration values for external consumption
Fieldtype::getCompatibleFieldtypes(Field $field) Fieldtypes or null Get an array of Fieldtypes that are compatible with this one
Fieldtype::getConfigAdvancedInputfields(Field $field) InputfieldWrapper Get Inputfields for advanced settings of the Field and Fieldtype
Fieldtype::getConfigAllowContext(Field $field) array Return an array of configuration field names from that are allowed in fieldgroup/template context
Fieldtype::getConfigArray(Field $field) array Same as getConfigInputfields but with definition as an array instead
Fieldtype::getConfigInputfields(Field $field) InputfieldWrapper Get any Inputfields used for configuration of this Fieldtype.
Fieldtype::importConfigData(Field $field, array $data) array Convert an array of exported data to a format that will be understood internally

Creating

Name Return Summary  
Fieldtype::createField(Field $field) bool Create a new field table in the database.
Fieldtype::getDatabaseSchema(Field $field) array Get the database schema for this field

Deleting

Name Return Summary  
Fieldtype::deleteField(Field $field) bool Delete the given field, which implies: drop the table used by the field.
Fieldtype::deletePageField(Page $page, Field $field) bool Delete the given Field from the given Page.
Fieldtype::deleteTemplateField(Template $template, Field $field) bool Delete the given Field from all pages using the given template, without loading those pages.
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(Field $field) Field Return a cloned copy of $field
Fieldtype::get(string $key) mixed Get a property from this Fieldtype’s data
Fieldtype::getInputfield(Page $page, Field $field) Inputfield or null Return new instance of the Inputfield module associated with this Fieldtype.
Fieldtype::install() (nothing) 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() (nothing) Uninstall this Fieldtype, consistent with optional Module interface
Fieldtype::upgrade($fromVersion, $toVersion) (nothing) Called when module version changes

Common

Name Return Summary  
Fieldtype::importValue(Page $page, Field $field, $value) string, int, array or object Given a value originally generated by exportValue() convert it to a live/runtime value.
Fieldtype::renamedField(Field $field, $prevName) (nothing)

Additional methods and properties

In addition to the methods and properties above, Fieldtype also inherits the methods and properties of these classes: