$fieldsnewField()

Create a new unsaved Field instance of the given type

Available since version 3.0.258.

Example

$field = $fields->newField('FieldtypeText');
$field->name = 'my_field';
$field->label = 'My Field';
$fields->save($field);

Usage

// basic usage
$field = $fields->newField($type);

// usage with all arguments
$field = $fields->newField($type, string $name = '', $options = []);

Arguments

NameType(s)Description
$typestring array

Fieldtype class name: 'FieldtypeText', 'Text', or 'text' all accepted or array containing 'type' and 'name' and anything else that would usually go in $options

$name (optional)string

Field name (optional)

$options (optional)string array

Field label or [key=>val] array of properties to set to Field (optional)

Return value

Exceptions

Method can throw exceptions on error:

  • WireException - if the fieldtype is not found


$fields methods and properties

API reference based on ProcessWire core version 3.0.259