$fields→newField()
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
| Name | Type(s) | Description |
|---|---|---|
$type | string 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 |
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