I'm trying to add a new field to a group using the API but it doesn't work (according to the docs it is supposed to be a key).
I have tried running the example code but the 'group_id' field is ignored when I add it to the field object sent to the update_field method:
ee()->load->library('api');
ee()->legacy_api->instantiate('channel_fields');
$field_data = array(
'site_id' => 1,
'group_id' => 1,
'field_name' => 'aaaa',
'field_label' => 'AAAA',
'field_type' => 'text',
'field_order' => 10,
'field_required' => 'y',
'field_search' => 'y',
'field_is_hidden' => 'n',
'field_instructions' => '',
'field_maxl' => 128,
'text_field_fmt' => 'none',
'text_field_show_fmt' => 'n',
'text_field_text_direction' => 'ltr',
'text_field_content_type' => 'all',
'text_field_show_smileys' => 'n',
'text_field_show_glossary' => 'n',
'text_field_show_spellcheck' => 'n',
'text_field_show_file_selector' => 'n',
);
ee()->api_channel_fields->update_field($field_data);
So I added a call to field_edit_vars prior to the update_field call as stated in the docs:
$vars = ee()->api_channel_fields->field_edit_vars(1, FALSE);
ee()->load->view('admin/field_edit', $vars, TRUE);
But I get 'Call to undefined method Api_channel_fields::field_edit_vars()'
I've also tried using the return value from the 'update_field' method, which according to the docs should be the new field id but it returns nothing.
How do I add the new field to a group?