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
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() | (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() Fieldtype::uninstall() Fieldtype::uninstall() | (nothing) | Uninstall this Fieldtype, consistent with optional Module interface | |
Fieldtype::upgrade() Fieldtype::upgrade($fromVersion, $toVersion) Fieldtype::upgrade($fromVersion, $toVersion) | (nothing) | 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::getFieldSetups() Fieldtype::getFieldSetups() Fieldtype::getFieldSetups() | array | ||
Fieldtype::importValue() Fieldtype::importValue(Page $page, Field $field, $value) Fieldtype::importValue(Page $page, Field $field, $value, array $options = array) | string float int array object | ) | |
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() | (nothing) | ||
Fieldtype::renamedField() Fieldtype::renamedField(Field $field, $prevName) Fieldtype::renamedField(Field $field, $prevName) | (nothing) | ||
Fieldtype::saveFieldReady() Fieldtype::saveFieldReady(Field $field) Fieldtype::saveFieldReady(Field $field) | (nothing) | ||
Fieldtype::savedField() Fieldtype::savedField(Field $field) Fieldtype::savedField(Field $field) | (nothing) |
Additional methods and properties
In addition to the methods and properties above, Fieldtype also inherits the methods and properties of these classes:
API reference based on ProcessWire core version 3.0.236