0

Anyone have any example or documentation to create a select field using the EE api in a channel group with name/value pairs for the select option. I cannot find anything on how to do that. I am able to create the select field itself, just not with name/value pairs for the options.

0

I finally figured this out, here is what I ended up with.

    ee()->load->library('api');
    ee()->legacy_api->instantiate('channel_fields');

    $field = ee('Model')->make('ChannelField');
    $field->group_id = $group_id;
    $field->site_id = $site_id;
    $field->field_name = $field_name;
    $field->field_type = 'select';
    $field->set(array(
        'field_label' => $field_label,
        'field_order' => $field_order,
        'field_required' => 'n',
        'field_search' => 'y',
        'field_is_hidden' => 'n',
        'field_instructions' => '',
        'field_maxl' => null,
        'field_show_fmt' => 'y',
        'field_fmt' => 'br',
        'text_field_show_fmt' => 'y',
        'text_field_text_direction' => 'ltr',
        'text_field_content_type' => 'any',
        'text_field_show_smileys' => 'n',
        'text_field_show_glossary' => 'n',
        'text_field_show_spellcheck' => 'n',
        'text_field_show_file_selector' => 'n',
        'field_pre_populate' => 'v',  
        'value_label_pairs' => array(
            'default' => 'Default',
            'option_2' => 'Option 2',
            'option_3' => 'Option 3'
        ),
    ));

    $field->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.