Cmb2: Support multilevel arrays within multicheck field type

Created on 29 Sep 2016  路  4Comments  路  Source: CMB2/CMB2

Expected Behavior:

When you create a new field with option values such as:

array(
                'name'    => 'Test Multi Checkbox',
                'desc'    => 'field description (optional)',
                'id'      => 'wiki_test_multicheckbox',
                'type'    => 'multicheck',
                'options' => array(
                    'check1' => 'Check One',
                    'check2' => 'Check Two',
                    'check3' => 'Check Three',
                    array(
                        'check1' => 'Check One',
                        'check2' => 'Check Two',
                        'check3' => 'Check Three',
                    )
                ),
            ),

You should see a multi-check option that's hierarchical as such:

screenshot at sep 28 20-50-35
as such:

Actual Behavior:

You get the following PHP error:

( ! ) Notice: Array to string conversion in /app/public/wp-content/plugins/give/includes/libraries/cmb2/includes/types/CMB2_Type_Multi_Base.php on line 42

Steps to reproduce (I have confirmed I can reproduce this issue on the trunk branch):

  1. Create a multicheck field type as above
  2. Turn on WP_Debug

    CMB2 Field Registration Code:

add_action( 'cmb2_admin_init', 'yourprefix_register_demo_metabox' );
function yourprefix_register_demo_metabox() {

    $cmb = new_cmb2_box( array(
        // Box Config...
    ) );

    $cmb->add_field( array(
        array(
                'name'    => 'Test Multi Checkbox',
                'desc'    => 'field description (optional)',
                'id'      => 'wiki_test_multicheckbox',
                'type'    => 'multicheck',
                'options' => array(
                    'check1' => 'Check One',
                    'check2' => 'Check Two',
                    'check3' => 'Check Three',
                    array(
                        'check1' => 'Check One',
                        'check2' => 'Check Two',
                        'check3' => 'Check Three',
                    )
                ),
            ),
    ) );
}
bug

All 4 comments

I trust you enough to assume right away that this is, for sure, a legit bug that could use addressing.

Thanks for the trust 馃憤

If I get the time I'll submit a PR with the fix to address it 馃帀

I there an update here or any new features to use instead?

Haven't seen anything for new movement for this issue specifically. New features available to everyone can be read about in the changelogs found at https://github.com/CMB2/CMB2/releases

Was this page helpful?
0 / 5 - 0 ratings