Fieldtypes / $fieldtypes

The $fieldtypes API variable is a collection of every installed Fieldtype module in the system

It provides a central place to look up, iterate, and retrieve Fieldtype instances by their class name or a short alias.

// Get the text fieldtype and its corresponding Inputfield for a field
$text = $fieldtypes->get('text');
$inputfield = $text->getInputfield($page, $fields->get('body'));

For the shared collection API — adding, removing, finding, sorting, slicing, and iterating — see WireArray. Fieldtypes is a WireArray subclass indexed by each fieldtype's class name.

Expand all      API reference

Getting a fieldtype

get($name)

Return a Fieldtype module for the given name. The name can be provided with or without the Fieldtype prefix, and module-name matching is case-insensitive.

// All of these return the same FieldtypeText instance
$ft = $fieldtypes->get('FieldtypeText');
$ft = $fieldtypes->get('text');

// Other examples
$ft = $fieldtypes->get('FieldtypePage');
$ft = $fieldtypes->get('page');
$ft = $fieldtypes->get('image'); // FieldtypeImage

If the requested fieldtype is installed but not yet loaded, get() resolves the module automatically. Like $modules->get(), it can also install an available but uninstalled Fieldtype module. It returns null when no matching module can be loaded or installed.

Because Fieldtypes implements magic __get(), you can also access common fieldtypes as object properties:

$text = $fieldtypes->FieldtypeText;
$text = $fieldtypes->text;
$file = $fieldtypes->file;
$url  = $fieldtypes->URL;

has($name)

Check whether the collection contains a fieldtype. Pass its full class name; unlike get(), this method does not resolve short aliases or load modules.

if($fieldtypes->has('FieldtypeComments')) {
    // Comments fieldtype is available
}

Iterating all fieldtypes

foreach($fieldtypes as $className => $fieldtype) {
    echo "<li>$className</li>";
}
Common fieldtype aliases

The PHPDoc for Fieldtypes exposes shorthand properties for the most common fieldtypes. Some properties have a |null type because the corresponding bundled Fieldtype module can be unavailable when it has not been installed. This indicates availability, not a Pro module.

Property / aliasFieldtype classNotes
checkboxFieldtypeCheckboxBoolean checkbox
commentsFieldtypeCommentsMay be null when not installed
datetimeFieldtypeDatetimeDate/time picker
emailFieldtypeEmailEmail address
fileFieldtypeFileOne or more files
floatFieldtypeFloatFloating-point number
imageFieldtypeImageOne or more images
integerFieldtypeIntegerWhole number
moduleFieldtypeModuleReference to another module
optionsFieldtypeOptionsMay be null when not installed
pageFieldtypePagePage reference
pageTableFieldtypePageTableTabular page references
pageTitleFieldtypePageTitlePage title (multi-language aware)
passwordFieldtypePasswordPassword hash
repeaterFieldtypeRepeaterMay be null when not installed
selectorFieldtypeSelectorMay be null when not installed
textFieldtypeTextSingle-line text
textareaFieldtypeTextareaMulti-line text
toggleFieldtypeToggleMay be null when not installed
URLFieldtypeURLURL

You can still access any installed fieldtype by its full class name even if it is not listed above.

Notes
  • API variable: $fieldtypes
  • Source file: wire/core/Fieldtypes/Fieldtypes.php
  • Extends: WireArray
  • Instantiation: ProcessWire builds this collection during bootstrap via $fieldtypes->init(); you normally access it through the $fieldtypes API variable rather than constructing it yourself.
  • Indexed by: each fieldtype's className() value (e.g. FieldtypeText).
  • Auto-resolution: get() loads an installed module on demand and may install an available but uninstalled module.
  • Related: Fieldtype, FieldtypeMulti, Fields, Field

API reference: methods, properties

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Fieldtypes class also inherits all the methods and properties of: WireArray and Wire.

Show $var?     Show args?       Only hookable?    

Common

NameReturnSummary 
$fieldtypes->eq($num)
None 
$fieldtypes->first()
None 
$fieldtypes->get(string $key)
Fieldtype null

Given a Fieldtype name (or class name) return the instantiated Fieldtype module.

 
$fieldtypes->getAll()
None 
$fieldtypes->getArray()
None

Below we account for all get() related functions in WireArray to preload the fieldtypes

 
$fieldtypes->getItemKey(Fieldtype $item)
string

Per the WireArray interface, Fields are indxed by their name

 
$fieldtypes->getIterator()
None 
$fieldtypes->getNext($item)
None 
$fieldtypes->getPrev($item)
None 
$fieldtypes->getRandom()
None 
$fieldtypes->getValues()
None 
$fieldtypes->init()
None

Construct the $fieldtypes API var (load all Fieldtype modules into it)

 
$fieldtypes->isValidItem($item)
bool

Per WireArray interface, items added to Fieldtypes must be Fieldtype instances

 
$fieldtypes->isValidKey($key)
bool

Per the WireArray interface, keys must be strings (fieldtype class names)

 
$fieldtypes->last()
None 
$fieldtypes->makeBlankItem()
null

Per the WireArray interface, return a blank copy

 
$fieldtypes->makeCopy()
None 
$fieldtypes->makeNew()
None 
$fieldtypes->pop()
None 
$fieldtypes->shift()
None 
$fieldtypes->slice($start)
None 
$fieldtypes->sort($properties)
None 

Properties

NameReturnSummary 
$fieldtypes->FieldtypeCheckbox FieldtypeCheckbox 
$fieldtypes->FieldtypeComments FieldtypeComments null 
$fieldtypes->FieldtypeDatetime FieldtypeDatetime 
$fieldtypes->FieldtypeEmail FieldtypeEmail 
$fieldtypes->FieldtypeFile FieldtypeFile 
$fieldtypes->FieldtypeFloat FieldtypeFloat 
$fieldtypes->FieldtypeImage FieldtypeImage 
$fieldtypes->FieldtypeInteger FieldtypeInteger 
$fieldtypes->FieldtypeModule FieldtypeModule 
$fieldtypes->FieldtypeOptions FieldtypeOptions null 
$fieldtypes->FieldtypePage FieldtypePage 
$fieldtypes->FieldtypePageTable FieldtypePageTable 
$fieldtypes->FieldtypePageTitle FieldtypePageTitle 
$fieldtypes->FieldtypePassword FieldtypePassword 
$fieldtypes->FieldtypeRepeater FieldtypeRepeater null 
$fieldtypes->FieldtypeSelector FieldtypeSelector null 
$fieldtypes->FieldtypeText FieldtypeText 
$fieldtypes->FieldtypeTextarea FieldtypeTextarea 
$fieldtypes->FieldtypeToggle FieldtypeToggle null 
$fieldtypes->FieldtypeURL FieldtypeURL 
$fieldtypes->URL FieldtypeURL 
$fieldtypes->checkbox FieldtypeCheckbox 
$fieldtypes->comments FieldtypeComments null 
$fieldtypes->datetime FieldtypeDatetime 
$fieldtypes->email FieldtypeEmail 
$fieldtypes->file FieldtypeFile 
$fieldtypes->float FieldtypeFloat 
$fieldtypes->image FieldtypeImage 
$fieldtypes->integer FieldtypeInteger 
$fieldtypes->module FieldtypeModule 
$fieldtypes->options FieldtypeOptions null 
$fieldtypes->page FieldtypePage 
$fieldtypes->pageTable FieldtypePageTable 
$fieldtypes->pageTitle FieldtypePageTitle 
$fieldtypes->password FieldtypePassword 
$fieldtypes->repeater FieldtypeRepeater null 
$fieldtypes->selector FieldtypeSelector null 
$fieldtypes->text FieldtypeText 
$fieldtypes->textarea FieldtypeTextarea 
$fieldtypes->toggle FieldtypeToggle null 

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.269