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.

Show class?     Show args?       Only hookable?    

Loading

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

Other

NameReturnSummary 
cloneField(Field $field)
FieldReturn a cloned copy of $field
get(string $key)
mixedGet a property from this Fieldtype’s data 
getInputfield(Page $page, Field $field)
Inputfield nullReturn new instance of the Inputfield module associated with this Fieldtype. 
install()
NoneInstall this Fieldtype, consistent with optional Module interface
longName string Long name of Fieldtype, which is typically the module title.  
name string Name of Fieldtype module.  
shortName string Short name of Fieldtype, which excludes the "Fieldtype" prefix.  
uninstall()
NoneUninstall this Fieldtype, consistent with optional Module interface
upgrade($fromVersion, $toVersion)
NoneCalled when module version changes

Common

NameReturnSummary 
getFieldClass()
stringGet class name to use Field objects of this type (must be class that extends Field class) 
importValue(Page $page, Field $field, $value)
string int array objectGiven a value originally generated by exportValue() convert it to a live/runtime value.
isDeleteValue(Page $page, Field $field, mixed $value)
boolIs given value one that should cause the DB row(s) to be deleted rather than saved? 
ready()
None 

For hooks

These methods are only useful for hooking and should not be called directly.

NameReturnSummary 
getFieldSetups()
arrayGet predefined setups for newly created fields of this type
renamedField(Field $field, string $prevName)
NoneHook called by Fields::save() after a field using this type has been renamed
saveFieldReady(Field $field)
NoneHook called by Fields::save() when a field is about to be saved
savedField(Field $field)
NoneCalled 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

TypeSummary
FieldtypeCheckboxThis Fieldtype stores an ON/OFF toggle via a single checkbox. The ON value is 1 and OFF value is 0.
FieldtypeCommentsField that stores user posted comments for a single Page
FieldtypeDatetimeField that stores a date and optionally time
FieldtypeEmailField that stores an e-mail address
FieldtypeFieldsetCloseClose a fieldset opened by FieldsetOpen.
FieldtypeFieldsetOpenOpen a fieldset to group fields. Should be followed by a Fieldset (Close) after one or more fields.
FieldtypeFieldsetTabOpenOpen a fieldset to group fields. Same as Fieldset (Open) except that it displays in a tab instead.
FieldtypeFileField that stores one or more files
FieldtypeFloatField that stores a floating point number
FieldtypeImageField that stores one or more GIF, JPG, or PNG images
FieldtypeIntegerField that stores an integer
FieldtypeModuleField that stores a reference to another module
FieldtypeOptionsField that stores single and multi select options.
FieldtypePageField that stores one or more references to ProcessWire pages
FieldtypePageTitleField that stores a page title
FieldtypePasswordField that stores a hashed and salted password
FieldtypeRepeaterMaintains a collection of fields that are repeated for any number of times.
FieldtypeTextField that stores a single line of text
FieldtypeTextareaField that stores multiple lines of text
FieldtypeToggleConfigurable yes/no, on/off toggle alternative to a checkbox, plus optional “other” option.
FieldtypeURLField that stores a URL

See also: Fieldtype modules in the modules directory

API reference based on ProcessWire core version 3.0.251