0

Is there a better way to tie into EE to create a grid field? During my module install, I am having it setup a new grid field to relate to a custom channel field group that setups up the required table information for a grid in my database. Example below. I feel there has to be a better/cleaner way to achieve this.

    // Create exp_channel_fields and assign by group_id
    ee()->db->insert(

        'exp_channel_fields',
            array(

                'site_id'               => 1,
                'group_id'              => 0,
                'field_name'            => 'menu',
                'field_label'           => 'Sidebar Nav',
                'field_instructions'    => 'Add links to display on sidebar nav.',
                'field_type'            => 'grid',
                'field_pre_populate'    => 0,
                'field_pre_channel_id'  => 0,
                'field_pre_field_id'    => 0,
                'field_ta_rows'         => 6,
                'field_maxl'            => 128,
                'field_required'        => 'n',
                'field_text_direction'  => 'ltr',
                'field_search'          => 'n',
                'field_is_hidden'       => 'n',
                'field_fmt'             => 'xhtml',
                'field_show_fmt'        => 'n',
                'field_order'           => 3,
                'field_content_type'    => 'any',
                'field_settings'        => $field_settings

            )
    );



    ee()->db->insert(

        'exp_grid_columns',
            array(

                'field_id'         => $exp_channel_field_id,
                'content_type'     => 'channel',
                'col_order'        => 0,
                'col_type'         => 'multi_select',
                'col_label'        => 'Nav Select',
                'col_name'         => 'nav_option',
                'col_required'     => 'n',
                'col_search'       => 'n',
                'col_width'        => 0,
                'col_settings'     => '{"field_fmt":"none","field_list_items":"link1\nlink2\nlink3","field_required":"n"}'

            )

    );
0

I believe the best approach to this was to tie directly into Expression Engine's Channel fields API.

https://ellislab.com/expressionengine/user-guide/development/api/api_channel_fields.html#fetch-all-fieldtypes

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.