Field represents a custom field that is used on a Page.

// Get an instance of Field
$field = $fields->get('field_name');

Field objects are managed by the $fields API variable.


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

Show $var?             Show args?        

Retrieval

NameReturnSummary 
$field->get(string $key)
mixedGet a Field setting or dynamic data property 
$field->getConfigInputfields()
InputfieldWrapperGet any Inputfields needed to configure the field in the admin.
$field->getDescription()
stringReturn field description for current language, or another specified language. 
$field->getFieldgroups()
FieldgroupsArrayReturn the list of Fieldgroups using this field. 
$field->getFieldtype()
Fieldtype nullReturn the Fieldtype module representing this field’s type. 
$field->getIcon()
mixed stringReturn the icon used by this field, or blank if none. 
$field->getInputfield(Page $page)
Inputfield nullGet the Inputfield module used to collect input for this field.
$field->getLabel()
stringGet field label for current language, or another specified language. 
$field->getNotes()
stringReturn field notes for current language, or another specified language. 
$field->getTable()
stringGet the database table used by this field. 
$field->getTemplates()
TemplatesArrayReturn the list of of Templates using this field. 
$field->numFieldgroups()
intReturn the number of Fieldgroups this field is used in. 

Access

NameReturnSummary 
$field->editRoles array Role IDs with edit access, applicable only if access control is enabled.  
$field->editable()
boolIs this field editable?
$field->useRoles bool Whether or not access control is enabled  
$field->viewRoles array Role IDs with view access, applicable only if access control is enabled.  
$field->viewable()
boolIs this field viewable?

Advanced

NameReturnSummary 
$field->setTable()
(nothing)Set an override table name, or omit (or null) to restore default table name 

Flags

NameReturnSummary 
$field->addFlag(int $flag)
$thisAdd the given bitmask flag 
Field::flagAccess const32Field is access controlled 
Field::flagAccessAPI const64If field is access controlled, this flag says that values are still front-end API accessible Without this flag, non-viewable values are made blank when output formatting is ON. 
Field::flagAccessEditor const128If field is access controlled and user has no edit access, they can still view in the editor (if they have view permission) Without this flag, non-editable values are simply not shown in the editor at all. 
Field::flagAutojoin const1Field should be automatically joined to the page at page load time 
Field::flagFieldgroupContext const2048Field has been placed in a runtime state where it is contextual to a specific fieldgroup and is no longer saveable 
Field::flagGlobal const4Field used by all fieldgroups - all fieldgroups required to contain this field 
Field::flagPermanent const16Field is permanent in any fieldgroups/templates where it exists - it may not be removed from them 
Field::flagSystem const8Field is a system field and may not be deleted, have it's name changed, or be converted to non-system 
Field::flagSystemOverride const32768Set this flag to override system/permanent flags if necessary - once set, system/permanent flags can be removed, but not in the same set(). 
$field->hasFlag(int $flag)
boolDoes this field have the given bitmask flag? 
$field->removeFlag(int $flag)
$thisRemove the given bitmask flag 

Properties

NameReturnSummary 
$field->allowContexts array Names of settings that are custom configured to be allowed for context.  
$field->collapsed int null The Inputfield 'collapsed' value (see Inputfield collapsed constants).  
$field->columnWidth int null The Inputfield column width (percent) 10-100.  
$field->description string Longer description text for the field  
$field->flags int Bitmask of flags used by this field  
$field->flagsStr string Names of flags used by this field (readonly)  
$field->icon string Icon name used by the field, if applicable  
$field->id int Numeric ID of field in the database  
$field->label string Text string representing the label of the field  
$field->name string Name of field  
$field->notes string Additional notes text about the field  
$field->prevFieldtype Fieldtype Previous Fieldtype, of type was changed  
$field->prevTable string Previously database table (if field was renamed)  
$field->required int bool null Whether or not this field is required during input  
$field->requiredIf string null A selector-style string that defines the conditions under which input is required  
$field->showIf string null A selector-style string that defines the conditions under which the Inputfield is shown  
$field->table string Database table used by the field  
$field->tagList array Same as $tags property, but as an array.  
$field->tags string Tags that represent this field, if applicable (space separated string).  
$field->textFormat int null The Inputfield 'textFormat' value (see Inputfield textFormat constants).  
$field->type Fieldtype null Fieldtype module that represents the type of this field  

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019
  • We added WebP image support this year and many have been adopting it in existing projects. We look at a process used for migrating existing websites to WebP images— from preliminary considerations to implementation & testing, w/lots of tips & tricks too: More
    16 August 2019
  • Core version 3.0.137 on the dev branch adds the ability to hook multiple methods at once, in a single call. This post details how it works and provides a useful example of how you might put it to use in your development environment— More
    2 August 2019

Latest news

  • ProcessWire Weekly #279
    This week in the 279th issue of ProcessWire Weekly we're going to introduce some of the latest third party modules out there, and highlight a brand new site of the week. Read on!
    Weekly.pw / 14 September 2019
  • ProcessWire 3.0.140 and FormBuilder v40
    This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140.
    Blog / 6 September 2019
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits