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.
Common
Name | Return | Summary | |
---|---|---|---|
$field->addTag() $field->addTag(string $tag) $field->addTag(string $tag) | array | Add one or more tags | |
$field->debugInfoSmall() $field->debugInfoSmall() $field->debugInfoSmall() | (nothing) | ||
$field->editUrl() $field->editUrl() $field->editUrl($options = []) | string | Get URL to edit field in the admin | |
$field->getContexts() $field->getContexts() $field->getContexts() | array | Get all contexts this field is used in | |
$field->getTags() $field->getTags() $field->getTags($getString = false) | array string | Get tags | |
$field->hasTag() $field->hasTag(string $tag) $field->hasTag(string $tag) | bool | Return true if this field has the given tag or false if not | |
$field->removeTag() $field->removeTag(string $tag) $field->removeTag(string $tag) | array | Remove a tag | |
$field->setSetupName() $field->setSetupName() $field->setSetupName(string $setupName = null) | string | Set setup name from Fieldtype to apply when field is saved |
Retrieval
Manipulation
Access
Name | Return | Summary | |
---|---|---|---|
$field->editRoles | array | Role IDs with edit access, applicable only if access control is enabled. | |
$field->editable() $field->editable() $field->editable($page = null, $user = null) | bool | Is 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() $field->viewable() $field->viewable($page = null, $user = null) | bool | Is this field viewable? |
Advanced
Name | Return | Summary | |
---|---|---|---|
$field->setTable() $field->setTable() $field->setTable($table = null) | (nothing) | Set an override table name, or omit (or null) to restore default table name |
Flags
Name | Return | Summary | |
---|---|---|---|
$field->addFlag() $field->addFlag(int $flag) $field->addFlag(int $flag) | $this | Add the given bitmask flag | |
Field::flagAccess const | 32 | Field is access controlled | |
Field::flagAccessAPI const | 64 | If 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 const | 128 | If 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 const | 1 | Field should be automatically joined to the page at page load time | |
Field::flagFieldgroupContext const | 2048 | Field has been placed in a runtime state where it is contextual to a specific fieldgroup and is no longer saveable | |
Field::flagGlobal const | 4 | Field used by all fieldgroups - all fieldgroups required to contain this field | |
Field::flagPermanent const | 16 | Field is permanent in any fieldgroups/templates where it exists - it may not be removed from them | |
Field::flagSystem const | 8 | Field is a system field and may not be deleted, have it's name changed, or be converted to non-system | |
Field::flagSystemOverride const | 32768 | Set this flag to override system/permanent flags if necessary - once set, system/permanent flags can be removed, but not in the same set(). | |
Field::flagUnique const | 256 | Field requires that the same value is not repeated more than once in its table 'data' column (when supported by Fieldtype) When this flag is set and there is a non-empty $flagUnique property on the field, then it indicates a unique index is currently present. When only this flag is present (no property), it indicates a request to remove the index and flag. When only the property is present (no flag), it indicates a pending request to add unique index and flag. @since 3.0.150 | |
$field->hasFlag() $field->hasFlag(int $flag) $field->hasFlag(int $flag) | bool | Does this field have the given bitmask flag? | |
$field->removeFlag() $field->removeFlag(int $flag) $field->removeFlag(int $flag) | $this | Remove the given bitmask flag |
Properties
Name | Return | Summary | |
---|---|---|---|
$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 null | Previous Fieldtype, if type was changed | |
$field->prevName | string | Previously used name (if field was renamed), 3.0.164+ | |
$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.236