Skip to content

Commit 6c79742

Browse files
committed
better example to create the field using models
1 parent bbb053a commit 6c79742

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

docs/development/models/channel-field.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ lang: php
2525
- `field_name`
2626
- `field_label`
2727
- `field_type`
28+
- `field_list_items` (can be empty)
29+
- `field_order`
2830

2931
### Optional
3032

3133
- `field_id` Key
3234
- `field_instructions`
33-
- `field_list_items`
3435
- `field_pre_populate`
3536
- `field_pre_channel_id`
3637
- `field_pre_field_id`
@@ -42,7 +43,6 @@ lang: php
4243
- `field_is_hidden`
4344
- `field_fmt`
4445
- `field_show_fmt`
45-
- `field_order`
4646
- `field_content_type`
4747
- `field_settings`
4848
- `legacy_field_data`
@@ -125,6 +125,13 @@ $field->site_id = ee()->config->item('site_id');
125125
$field->field_name = 'my_field_name';
126126
$field->field_label = 'Field Label';
127127
$field->field_type = 'text';
128+
$field->field_list_items = '';
129+
$field->field_order = 1;
130+
131+
// Set field-specific settings
132+
$settings = $field->getSettingsValues();
133+
$settings['field_settings']['field_show_file_selector'] = 'y';
134+
$field->setProperty('field_settings', $settings['field_settings']);
128135

129136
// Validate and Save.
130137
$result = $field->validate();
@@ -138,7 +145,7 @@ if ($result->isValid())
138145
$field->field_id;
139146
```
140147

141-
Field types `Relationships` `Grid` and `Fluid` require additional steps. Their data will be `NULL`.
148+
Field types `Relationships`, `Grid` and `Fluid` require additional steps. Their data will be `NULL`.
142149

143150
### Add Field to a Field Group
144151

0 commit comments

Comments
 (0)